Tuesday, May 11, 2010

Fixing Session error with custom SharePoint master pages

Recently one of my colleague asked me to look in to a weird problem he is facing with regards to SharePoint master page. in this SharePoint site he has a Pages library that publishes plain aspx pages that implements some of his Session related functionality in code behind. all went well until he changed the master page to a custom master page which was uploaded in to the master page gallery. suddenly we were getting the following error in the aspx page.
the funniest(or the weirdest) thing is that if the master page is changed back to any out of the box master page, the site works fine. after some investigation I realized that if the site master page is changed to a customized master page (or even to a custom master page that has been uploaded in to master page gallery through SharePoint UI) the aspx page breaks with the error. 
"Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration."
Straight forward, Right? so, checked the web.config over and over again, but the setting is set to enable the session state. after some Googling I realized that every body is suggesting that the web.config should be corrected. but, it is corrected. so, what's next?
So, what is the difference between OOB master pages and the custom master pages that are uploaded through SharePoint UI or customized through SharePoint Designer? the simple difference is the way how they ended up in the gallery. OOB master pages are uploaded via feature activation and sit in the WFE's file system where as other reside in the site content data base. so, I decided to create a file upload feature. please check Heather Solomon's article on how to create a master page feature.
By activating the new master page feature, I got the new master page available in the master page gallery. then I set the new master page of the site. walla, it worked!!! No more Session errors in the custom aspx page.
Even though I got the problem solved for my colleague, I still don't understand what caused the problem. so, if anybody knows the cause of the problem I would appreciate comments on this thread.

No comments: