Skip to main content

Posts

Showing posts from May, 2011

Enable Session State in SharePoint 2010

You would have noticed that after installing SharePoint 2010 and deploying your custom solutions, code which is dependent on Session variables would not work as expected. That is because the Session state is not enabled by default. You just need to run this cmdlet in Powershell and boom Session starts working. Enable-SPSessionStateService –DefaultProvision A new service Application by name "SharePoint Server ASP.NET Session State Service" should be available. The web.config will have this additional entry under configuration/system.webserver/modules Also dont forget to change the attribute "enableSessionState" to true in the page Element.

SPWebConfigModification

SharePoint offers the SPWebConfigModification class to update web.config entries. We can have a Feature receiver at the Web Application scope and on activation propgate the web config changes to all the WFE servers .. This is good right? But the caveat is that the class is not so flexible. It does not allow us to reorder the entries within a section which is really important in case of custom Http modules ad handlers. Hope MS takes care of this in the next update ..Hers is a sample code to add the connection strings section and update the enableSessionstate attribute. SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent; SPWebConfigModification wcupdate1 = new SPWebConfigModification(); wcupdate1.Owner = "Any Name"; wcupdate1.Name = "enableSessionState"; wcupdate1.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute; wcupdate1.Path = "configuration/system.web/pages"; wcupdate1.Value = "true"; //...