开发者

Session value set in Session_Start not available in Page_PreInit

I am having an intermittent problem with an ASP.NET 4.0 Web Forms application.

In Session_Start, I store the master page file path in the session:

protected void Session_Start(Object sender, EventArgs e)
{
   // Not shown: get master page path from database

   Session["MasterPagePath"] = PathIGotFromTheDatabase;
}

Then in my pages' Page_PreInit, I use that session value to set the Page.MasterPageFile

protected void Page_PreInit(object sender, EventArgs e)
{
    Page.MasterPageFile = Session["MasterPagePath"] + @"/MyMasterPage.Master";
}

This works 99% of the time, but occasionally something breaks, and Session["MasterPagePath"] is null. The users report that they have to close all of their active browser sessions in order to use the site again.

My understanding is that since I populate the Session["MasterPagePath"] in Session_Start, it should always be available in my pages' PreInit method. If my session had expired, it would always be repopulated by Session_Start before Page_PreInit is called.

Am I missing something here? Under what conditions could what I开发者_如何学编程 describe happen? I am using InProc session state for what it's worth.


I don't think Session objects added on Application_Start are available at control level. Application["myObj"] would be available but for all users.

More information about the life cycle here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜