I have a custom MembershipProvider that I'm using in an ASP.NET 2.0 application. Inside of the class that extends membership provider, I have a function called AttemptLogin()
that sets session variables if the user is valid. Inside that function, are开发者_运维技巧 a number of session variable assignments similar to the following:
HttpContext.Current.Session["id"] = "12345";
AttemptLogin()
is being called by the Application_BeginRequest
function in global.asax. This code works fine when I open it in visual studio, and then run it in the built-in development server by clicking "Start Debugging". However, when I deploy it to our testing server (Windows 2003 Server 64-bit running IIS in 32-bit mode), execution breaks when it reaches the code above, giving me the following message:
[NullReferenceException: Object reference not set to an instance of an object.] CustomMembershipProvider.AttemptLogin() in c:\Inetpub\wwwroot\Josh\App_Code\CustomMembershipProvider.cs:1097 ASP.global_asax.Application_BeginRequest(Object sender, EventArgs e) in c:\Inetpub\wwwroot\Josh\Global.asax:14 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
How can I access the session state successfully in this situation? Why does it work locally and not on the server?
Session Variables aren't available at Application_BeginRequest you should look later in the pipeline by handling the Application_AcquireRequestState in your global.asax, I'm honestly puzzled why you don't get a null ref on your dev box.
Check the web.config file on the server and make sure sessionState mode is enabled
<sessionState mode="InProc" />
精彩评论