日期:2014-05-17 浏览次数:20624 次
<httpHandlers>
    <clear />
</httpHandlers>
<httpModules>
    <clear />
    <add name="HttpModule" type="Xy.Web.HttpModule,Xy.Web" />
</httpModules>
HttpApplication.Context.Session
HttpContext.Current.Session
public class SessionModule : IHttpModule 
    {
        public void Init(HttpApplication context)
        {
            context.BeginRequest += BeginTransaction;
            context.EndRequest += CommitAndCloseSession;
            context.PreRequestHandlerExecute += PreRequestHandlerExecute;
        }
        public void Dispose() { }
        public void PreRequestHandlerExecute(object sender, EventArgs e)
        {
            var context = ((HttpApplication)sender).Context;
            context.Session["some_sesion"] = new SomeObject();
        }
...
}
------解决方案--------------------
如果在HttpModule中使用session,则必需在加载在
HttpModule.AcquireRequestState()
                       |
HttpModule.PreRequestHandlerExecute()
否则是读取不到Session.
参见
http://forums.asp.net/p/1098574/1665773.aspx