Thursday, January 14, 2016

ASP.NET page life cycle

It is very much similar as ASP.NET page life cycle with enhancement of few events.
OnInit: This method handles initialization of the control.
OnLoad: This event handles the Load event and also used for initialize the control. But it is not intended for loading data or other processing functionality.
CreateChildControls: This creates any child controls.
EnsureChildControls: This method ensures that CreateChildControls has executed. EnsureChildControls method must be called to prevent null reference exceptions.
SaveViewState: View state of the web part saved.
OnPreRender: This method handles or initiates tasks such as data loading that must complete before the control can render.
Page.PreRenderComplete: The page fires the PreRenderComplete event after all controls have completed their OnPreRender methods.
Render: This method is used to render everything.
RenderContents: Renders the contents of the control only, inside of the outer tags and style properties.
OnUnload: Performs the final clean up.
Initial Load:
Events fired when a web part is initially loaded. 
Post-back:
     OnInit
     LoadViewState
     EnsureChildControls
     CreateChildControls
     EnsureChildControls
    CreateControlCollection
    EnsureChildControls (many)
    OnLoad
    btnUpdate_Click
    OnBubbleEvent
    EnsureChildControls
    OnPreRender
    EnsureChildControls (many)
    SaveViewState
    RenderControl
    Render
    RenderControl
    RenderContents
    RenderChildren
    OnUnload
    Dispose

Like Asp.Net life cycle there is also Web Part life cycle. So it is better to understand the web part life cycle. I’ve explained some of them which are used by every developer to cover most of the requirements:
OnInit: This method handles initialization of the control.
OnLoad: This event handles the Load event. This is also used for initialize the control but is not intended for loading data or other processing functionality.
CreateChildControls: This is the most popular event in web part life cycle. This creates any child controls. So if you are adding any control to display then you have to write in this method.
EnsureChildControls: This method ensures that CreateChildControls has executed. EnsureChildControls method must be called to prevent null reference exceptions.
SaveViewState: View state of the web part saved.
OnPreRender: This method handles or initiates tasks such as data loading that must complete before the control can render.
Page.PreRenderComplete: The page fires the PreRenderComplete event after all controls have completed their OnPreRender methods.
Render: This method is used to render everything.
RenderContents: Renders the contents of the control only, inside of the outer tags and style properties.
OnUnload: Performs the final cleanup.

Wednesday, January 6, 2016

Blob Cache in SharePoint

1.What is Blob Cache?

Disk-based Caching for Binary Large Objects
Disk-based caching controls caching for binary large objects (BLOBs) such as image, sound, and video files, as well as code fragments. Disk-based caching is extremely fast and eliminates the need for database round trips. BLOBs are retrieved from the database once and stored on the Web client. Further requests are served from the cache and trimmed based on security.

2.Enabling and modifying disk-based caching for SharePoint sites.

Disk-based caching is disabled by default. To enable and customize the disk-based cache, you must modify the following statement in the web.config file for the SharePoint Web application.
By default, it looks like this: 
<BlobCache location="C:\blobCache" path="\.(gif|jpg|png|css|js)$" maxSize="10" enabled="false" />
In order to improve the performance of your site, the BlobCache should be enabled. 
<BlobCache location="C:\blobCache" path="\.(gif|jpg|png|css|js)$" maxSize="10" enabled="true" />
Example:
<BlobCache location="C:\blobCache" path="\.(gif|jpg|png|css|js)$" maxSize="10" max-age="86400" enabled="false"/>
In the preceding example:
• location is the directory where the cached files will be stored 
• path specifies in the form of a regular expression which files are cached based on the file extension 
• maxSize is the maximum allowable size of the disk-based cache in gigabytes 
• max-age specifies the maximum amount of time in seconds that the client browser caches BLOBs downloaded to the client computer. If the downloaded items have not expired since the last download, the same items are not re-requested when the page is requested. The max-age attribute is set by default to 86400 seconds (that is, 24 hours), but it can be set to a time period of 0 or greater. 
• enabled is a Boolean that disables or enables the cache.

3. Flushing the Disk-based Cache:

We can flush the current site collection object cache. To do this, browse to the following location on the web site, 
Site collection administration -> site collection object cache -> disk based cache reset.
If we have multiple WFEs in the farm, each WFE will maintain its own copy of Disk-based Cache. SharePoint does not have a Web user interface (UI) to flush the disk-based cache on all the servers in a farm and neither is there an option to select a specific WFE.
4.The option provided in the Administration page for flushing the cache is only to the flush the cache on the web front end to which you are currently browsing.
if you would like to flush the complete binary large object (BLOB) caches associated with a specific Web Application on different Web front-end computers in a farm, then you can use the STSADM command to do so.
STSADM -o setproperty -propertyname blobcacheflushcount -propertyvalue 11 -url http://mywebapp:port

5.Internals of the blob cache functionality within SharePoint:

After enabling blob cache in web.config, do an IISRESET and browse to the /settings.aspx first, instead of home page (Collaboration portal site).
When we browse to the settings.aspx, it will create the following files change.bin, dump.bin and flushcount.bin (all the files will be 1KB in size).
Browse to the home page now, it will create a folder PUBLISHINGIMAGES, all the images rendered from the database will be stored here and the above bin files will also get updated (we can see the difference in file size).
Every time when a new image file is rendered from the database, the image folder gets a copy of the image. The bin files (index) will get updated with an additional entry for the new file.
Every request from client will check the index file first. It will only check the cache index and not the image folder directly for the image. If the index file does not have an entry for the image, then the request is served from the database. During this time, a copy of the image will be stored in the images folder and the index file also gets updated, so that the next request will not go to the database.

6.What happens I manually delete just the image file in the cache folder or the image file in the cache folder gets corrupted?

We will not see the image on the client page; we get a broken image ‘X’.

7.How are these cache files stored?

Filename.extension.cache is the file naming format.

8.What can I do if the cached file gets corrupted?

Recommendation: We can reset the index file. Site settings -> Site collection object cache -> Check the box for “Force this server to reset its disk based cache”. It will completely delete all the images and reset the bin files back to 1KB, so that next request will go to database and the complete index will get rebuilt.
Workaround: If you do not want to reset the complete index. Find out the missing image and copy just that file to the cache folder, name it as “filename.extension.cache” 
Refresh the page now; it should pick up the image.

9.How is the Index file maintained?

Every time when the web.config initializes, the index file is loaded from the blobcache folder to memory. All new entries will keep getting updated in index file when in memory. 
IISRESET /stop will flush the updated index file from memory to disc within the blobcache folder. 
IISRESET /start will load the index file from blobcache folder to memory. 
As long as the application pool is alive the index file will be getting updated in memory itself.

10.Can an Index file get corrupt?

Index file corruption is possible only when IIS crash or the index file is overwritten with wrong information. When IIS tries to load the index file from blobcache to memory and identifies that it is a corrupted file (not a valid file), it will get completely rebuilt (flush) as fresh file (1KB), all the old entries and images will be lost.

11.In a farm environment, is there any way of having all the WFEs' blob caches synchronized among each other?

No, this cannot be done because SharePoint maintains the index and the cache files individually on each server.

12.In a single WFE environment using web gardening, how does blob caching function? Is there any sync that happens among the working processes?

Web gardening is not supported.

13.What would be the best way of using blob cache in a farm environment (best practices)?


If the requirement is to “centralize” static cached files, then 3rd party content distribution network (CDN) solutions like Akamai need to be used.
What are the limitations of SharePoint and blob caching in a farm environment? 
a. Blob caching does not work with Web Gardening. 
b. Blob caching does not synchronize data across WFEs – so we might be seeing different versions of the files for a short duration across different WFE servers.

Complete reporting services integration with SharePoint 2013



In this article we learn how to configure reporting services integration with SharePoint 2013. SQL Server 2012 Service Pack 1 (SP1) is a version of Microsoft SQL Server 2012 that supports Microsoft SharePoint 2013 Excel Services usage of Excel workbooks containing data models and Reporting Services Power View reports.

What's new in SQL Server 2012 SP1 Installation for Business Intelligence:
·                     PowerPivot for SharePoint: Analysis Services provides a backend service for Excel Services to load, query, and refresh PowerPivot data models so that users can interact with Excel workbooks that contain data models in the browser. Analysis Services in SharePoint mode is fully independent of, and external to, SharePoint, although the server running Analysis Services must be on the same network and the Active Directory Domains Services (AD DS) forest as the SharePoint farm. You install and manage Analysis Services using SQL Server installation media and tools. Choose the setup option PowerPivot for SharePoint. After you install Analysis Services in SharePoint mode, the only additional configuration tasks are to grant the SharePoint services account's server administrator permissions in Analysis Services and to configure Excel Services to point to the Analysis Services instance.
 
·                     spPowerpivot.msi: A Windows Installer package available with the SQL Server 2012 SP1 Feature Pack. The installer enhances the PowerPivot for SharePoint experience with more features such as PowerPivot Gallery and Schedule Data Refresh. The .msi deploys Analysis Services client libraries, the PowerPivot for SharePoint 2013 Configuration tool, and copies PowerPivot for SharePoint 2013 installation files to SharePoint servers.
 
·                     Reporting Services: The overall Reporting Services installation remains the same with SQL Server 2012 SP1 as it was with SQL Server 2012. There is an updated Reporting Services for SharePoint add-in that supports SharePoint 2013.
we are only discussing the reporting services configuration. We will see the remaining sessions, described previously, in future articles. Fundamentally, there are no real differences with how this installs when compared to installing SSRS 2012 on a SharePoint 2010 farm in SharePoint mode, so if you’ve landed here looking for 2010 information, it should be valid, but the screens will look a little different.
To start with, it’s important to understand that SSRS will install as a SharePoint service application. This obviously means that it must be installed on a machine that is part of the SharePoint farm. What this does NOT mean is that you should install SharePoint on your SQL server and join it to the farm (please DON’T do that!). In a single SharePoint front end environment it is much better to add SSRS to your SharePoint server than it is to add SharePoint to your SQL server. Obviously, if you have a separate SharePoint application server, that’s the best place for it.
To install, obtain the SQL Server 2012 SP1 (or greater) media and mount it on your SharePoint server. Run the installer, choose new install and follow the prompts. Eventually you will get to the feature section screen, and assuming that machine has no prior SQL on it will look something like the following when completed.

You’ll notice that everything selected is under the Shared Features section, which means that it is not installed as part of a SQL instance. In fact, you’ll notice that we don’t have the data engine installed at all. The two Reporting Services options shown are the only items that are actually required for SSRS Integrated mode to work. As you can see, I’ve also selected SQL Server Data Tools (formerly BIDS) and Management Tools as well. I like to install these tools as a matter of course on SharePoint servers, as they can come in handy for connectivity testing or quick BI project building.
Follow the remaining prompts until the installation is complete.
Another thing that you should note is that the order of operations is important here. If you install Reporting Services – SharePoint prior to installing SharePoint on the farm, the option to create a Reporting Services application will not appear. That’s because it won’t be registered with the farm as a service application. If this happens, you can run the following PowerShell to register the Service Application
Install-SPRSService
Install-SPRSServiceProxy
Once registered, the service application can be created as below. If you install Reporting Service – SharePoint after the server has been joined to the farm, then the above steps are taken care of for you automatically.
The next thing that you need to do is to provision the service application. From Central Administration, navigate to Manage Service applications. Then, from the new menu, Select SQL Server Reporting Services Service Application.


Fill out the resulting form as appropriate, and select OK. Make sure that you navigate to the bottom of the form and select the applications to activate SSRS on.


 
Click on Provision Subscripts and Alerts
 
Click on Download script, save script and run in your SQL Server
 
 
Back in to the Provision Subscripts and Alerts settings, I have entered sureshnv\Administrator since it was sysadmin on the SQL Server.
 

Click ok. Once the service application and proxy have been created, click on it to access the management screen.
 
You’ll want to access each of the sections and fill out the appropriate options for your installation. The instructions are fairly self-explanatory, so I won’t go into them here. At a minimum, you should back up your encryption key in the key management section, Set your unattended execution account (the default account to use when no credentials are available), and your email server settings if you want to be able to deliver reports via email. If you want to enable self-service subscriptions and alerts, fill out that section, and it contains instructions for setting up the SQL agent service to support it.
The most important section is System Settings, which controls the bulk of how Reporting Services will run. Clicking on it accessed the service itself, and it’s the first place that you’ll see an error if you have configuration problems. In early builds, I have seen an error similar to the following:
The requested service, ‘http://localhost:5555/SecurityTokenServiceApplication/securitytoken.svc/actas’ could not be activated
(5555is a local port which varies from farm to farm)
This indicated a problem with the SecurityTokenService, which you can see by accessing IIS. After doing a little poking around, I tried to access the service directly in a browser via its base url:
I was then presented with an error indicating that the server was too low on memory. The solution? Allocate more RAM. It was running with 4 GB and only SharePoint installed, but it did have most of the service applications activated. The lesson – if you want all the services to work, give your server enough memory. Bumping it to 8 GB did it in my case.
If you can access your system settings, then you should be good to go. The next step is to enable SSRS in you site collections Log in to the site with Admin credentials. In SharePoint 2013, apps and libraries are added using the little gear symbol in the upper right corner.  Click the gear and click ‘Add an App’.
 

From the list of Apps, click ‘Document Library’.  I named mine ‘Reports’
 
  Once the App is created, you will be presented with an empty library.  We need to change the library to accept SSRS items, so click the ‘Library Settings’ button.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO-VHydaM3Naaou6xZx47UpCib36nwZ_mWW7A4M0-awF9yccAK9g7tiskfpkijHKKUeqoW9C7l_RxVMaYZzV3Qc3j_1K8aRlu5tLdYG099_-TcAHJ1aADq3RtxJiFxowQCHNlk6NFE80Vq/s400/pola.jpg

  In the settings, click Advanced Settings so we can start managing the content types.

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkqYMMGwC0VEt6dcquE0JgF84kMTSCusHQ4QKqB726XpAaMXDdMu4DeZtfAIobKmBTWOcshbOhoIh3EjG1nPsYJn5dQ0R5g_cGzrzOCcpWSOR6VF8bnlTU43LhCuh0lcgLIrX3mCkvd64C/s400/content.jpg

 Now you will have the option to select Content Types.  Just under the list of settings, is a new section ‘Content Types’.  Under that, Click ‘Add from existing site content types.

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-uBtDijBZMZck0inC0c986WeeUkQ2GAu46FjCTNXkUxquxVv5sMzu3SvZGLQfEzAG1wx5hu9y8RAXSrx1gNo7Jr_3eF8nH0_wi_qQo0KARpuqm3wmV37OmG0-AqtcJ68CGFaKrfeFVmv-/s400/exit.jpg


 A new window opens with selector boxes allowing you to choose content types.
Highlight in the left box and click Add to add the following types:
·         Report
·         Report Builder Model
·         Report Builder Report
·         Report Data Source
It should now look as follows.

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd32D1H2z3pdjmdyJeNR9veCvKeyLgeA-9c-p-tzRatPjgX4A4A67-344mDDNchGW2b6WhzYJLh-WPMxitkVLLIWuwXJWi-ykhroJqfswXCEHLteCx6VN3x9g0K3Gr7I2izkJR1lC7wlE_/s400/look.jpg

Click OK.
You have now configured SharePoint 2013 to work with SQL Server Reporting Services in Integrated mode.
You should now be able to deploy reports.  In my example library above named ‘Reports’ on a server named DEVBOX the deployment URL will be:  http://devbox/Reports
If you want to separate shared data sources and data set files,  you need to navigate to the empty library and use the Files menu ‘New Folder’ button create the folders before deploying the project.  Each setting requires the full URL to the subfolder.  If you used spaces, click the elipses (…)  to get the proper url.
Here is the view of an SSRS Project Properties box ready to deploy.


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguBDaougLXh1zpq2WbmkN6Dld01uywPd4fxE3F6E7O3W7zb9igdl259pUXspv9NMqAaVPBvZC70DRo-m_80UyQevDMvwd3-Ed9PolmiFy2yZZPFvBIP_uhqmsLT_KddosrndgYb2WSABWl/s400/ok.jpg

If this has been helpful, leave a comment… :)