日期:2014-05-17  浏览次数:20525 次

HttpModule中进行了url重写,没有aspx,如何访问到session?
C# code

private void context_AcquireRequestState(object sender, EventArgs e)
        {
                string validateCode = StringHelper.GetRandNum().ToString();
                context.Session["ValidateCode"] = validateCode;//session为null
                context.Response.ContentType = "image/gif";
                context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                context.Response.Cache.SetNoStore();
                context.Response.Buffer = true;
                context.Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
                context.Response.Expires = -1;
                context.Response.CacheControl = "no-cache";
                context.Response.AddHeader("Pragma", "No-Cache");
                context.Response.BinaryWrite(ValidateHelper.getVerificationImage(validateCode).ToArray());
            }

实现了IRequiresSessionState,标记了EnableSession=true,无效········

特来求助··

------解决方案--------------------
web.config中注册了吗?

和你重写URL应该没关系的,即使是一张图片的请求也能得到session
------解决方案--------------------
关键是重写URl后还有session吗?有的话 直接取不就行了吗 string test=session["Test"].toString();
------解决方案--------------------
静态文件不通过HttpModule吧,iis直接处理了。哪还有session。要处理好像得在web.config和iis注册设置吧。忘了。。。
------解决方案--------------------

httpcontext.current.session 这个不行么?