无法在IHttpModule中使用会话

时间:2017-03-14 15:41:37

标签: c# asp.net .net http httpmodule

我正在尝试在OnBeginRequest中使用会话但不起作用。

其他问题发布的答案显示它适用于不同的事件处理程序,但我需要会话专门为OnBeginRequest工作

因为,当前的浏览器url只会出现在OnBeginRequest中,我可以重写,当有重定向时,如果它是其他一些事件处理程序,我将获得HttpContext.Current.Request中页面的所有url。网址。但我只需要HttpContext.Current.Request.Url中的浏览器URL。

void OnBeginRequest(object sender, EventArgs e)
       {
           HttpApplication appObject = (HttpApplication)sender;
           HttpContext contextObject = appObject.Context;
           string rpath = HttpContext.Current.Request.Url.ToString();

contextObject.Session["Session"] = "Assigning here"; //But after assigning it is null
                               string rewritestr = HttpContext.Current.Request.Url.AbsolutePath.Replace(subFolName, "");
                               rewritestr = rewritestr.Replace("//", "/");
                               contextObject.RewritePath(rewritestr);

           }

我们如何分配这个?当我们重定向到另一个页面并执行到达此处时,使用相同的会话。

0 个答案:

没有答案