Handle Session Start for SharePoint 2010 applications
I ran into a situation where i have to handle the session start of a SharePoint application. I dint find much information about it in the internet, so i decided to post one myself.
There are two main steps for this.
1. Enable sessions for your SharePoint application
2. Handle the Session_Start event.
To enable Sessions for SharePoint application, make the following changes in your web.config
1. Make enableSessionState=true
2. Replace the <httpModules/> with the below
<httpModules >
<add name="Session" type="System.Web.SessionState.SessionStateModule" />
</httpModules >
3. Add the Session module for your SharePoint site from the IIS Manager.
Open IIS Manager and expand sites.
Select your site and double click on Modules.
Click on Add Managed Module on the right hand side Actions menu
Give a name to the module and select the SessionStateModule from the drop down
This will enable sessions for your SharePoint web application.
Now you have to handle the Session_Start of your application.
For this create a normal ASP.NET web application in Visual Studio.
Add Global.asax and write your code in the Session_Start event.
To make this Global.asax usable by your SharePoint application, you have to make one small change to it.
Make the class of your Global.asax inherit from Microsoft.SharePoint.ApplicationRuntime.SPHttpApplication.
Just replace the HttpApplication with Microsoft.SharePoint.ApplicationRuntime.SPHttpApplication.
Go to the virtual directory of your SharePoint web application and do the following.
1. Replace the existing global.asax with the newly created file.
2. Copy the dll generated for your Visual Studio project and paste in the bin directory of your SharePoint web application.
There are two main steps for this.
1. Enable sessions for your SharePoint application
2. Handle the Session_Start event.
To enable Sessions for SharePoint application, make the following changes in your web.config
1. Make enableSessionState=true
2. Replace the <httpModules/> with the below
<httpModules >
<add name="Session" type="System.Web.SessionState.SessionStateModule" />
</httpModules >
3. Add the Session module for your SharePoint site from the IIS Manager.
Open IIS Manager and expand sites.
Select your site and double click on Modules.
Click on Add Managed Module on the right hand side Actions menu
Give a name to the module and select the SessionStateModule from the drop down
This will enable sessions for your SharePoint web application.
Now you have to handle the Session_Start of your application.
For this create a normal ASP.NET web application in Visual Studio.
Add Global.asax and write your code in the Session_Start event.
To make this Global.asax usable by your SharePoint application, you have to make one small change to it.
Make the class of your Global.asax inherit from Microsoft.SharePoint.ApplicationRuntime.SPHttpApplication.
Just replace the HttpApplication with Microsoft.SharePoint.ApplicationRuntime.SPHttpApplication.
Go to the virtual directory of your SharePoint web application and do the following.
1. Replace the existing global.asax with the newly created file.
2. Copy the dll generated for your Visual Studio project and paste in the bin directory of your SharePoint web application.
Before this we have to enable the SessionStateService. Please check this reference for enabling session state
ReplyDeletehttp://sharepoint-community.net/profiles/blogs/asp-net-session-state-implementation-in-sharepoint