在我的程序中,我试图在IHttpModule中使用会话变量。以下是我的代码。在VS 2010开发服务器中,这可以正常工作。但是当我尝试在IIS7中调试时,它显示异常System.Web.HttpException: Session state is not available in this context
。
那么为什么会话在开发服务器上可用,但在IIS 7上不可用呢?
using System;
using System.Web;
public class Globalizer : IHttpModule
{
public void Init(HttpApplication context)
{
context.AcquireRequestState += new EventHandler(setLanguage);
}
public void Dispose(){}
public void setLanguage(Object sender, EventArgs i_eventArgs)
{
HttpApplication http_application = sender as HttpApplication;
http_application.Session["language"] = "test";
}
}
IRequiresSessionState
的正确方式吗? - Nayana Adassuriya