【发布时间】:2011-03-16 17:10:01
【问题描述】:
我有一个在 ASP.NET 2.0 应用程序中使用的自定义 MembershipProvider。在扩展成员资格提供程序的类中,我有一个名为AttemptLogin() 的函数,如果用户有效,它会设置会话变量。在该函数内部,有许多类似于以下内容的会话变量赋值:
HttpContext.Current.Session["id"] = "12345";
AttemptLogin() 正在被 global.asax 中的 Application_BeginRequest 函数调用。当我在 Visual Studio 中打开此代码时,它运行良好,然后通过单击“开始调试”在内置开发服务器中运行它。但是,当我将它部署到我们的测试服务器(Windows 2003 Server 64 位,在 32 位模式下运行 IIS)时,当它到达上面的代码时执行中断,给我以下消息:
[NullReferenceException:对象引用未设置为对象的实例。] c:\Inetpub\wwwroot\Josh\App_Code\CustomMembershipProvider.cs:1097 中的 CustomMembershipProvider.AttemptLogin() c:\Inetpub\wwwroot\Josh\Global.asax:14 中的 ASP.global_asax.Application_BeginRequest(Object sender, EventArgs e) System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
在这种情况下如何成功访问会话状态?为什么它在本地工作而不是在服务器上工作?
【问题讨论】:
-
为什么不从 Session_Start 调用 AttemptLogin()?
-
@Alex - 我需要这个电话在任何时候发生。这是由于我们有一些不稳定的会话共享代码,将在不同平台上运行的几个不同应用程序的会话联系在一起。 kd7 建议的 Application_AcquireRequestState 方法似乎可以满足我的需要。
标签: asp.net iis session asp.net-2.0