0

我在 HTTPModule 的帮助下编写一个类,以在访问任何页面之前检查会话中的用户身份。如果会话中的变量为空或为空,我将在会话过期页面中重定向用户。

类中的代码:

public class SessionUserValidation : IHttpModule
{
    public void Dispose()
 {

}

public void Init(HttpApplication application)
{
    application.PreRequestHandlerExecute += new     
      EventHandler(application_PreRequestHandlerExecute);
}


private void application_PreRequestHandlerExecute(object sender, EventArgs e)
{
    HttpApplication application = (HttpApplication)sender;
    IHttpHandler handler = application.Context.Handler;
    Page reqPage = handler as Page;
    if (reqPage != null)
    {
        reqPage.PreInit += new EventHandler(CustomModule_Init);
    }
}


private void CustomModule_Init(object sender, EventArgs e)
{

    Page Page = sender as Page;
    if (!Page.Request.Url.ToString().Contains("mySessionExpired.aspx") &&
        !Page.Request.Url.ToString().Contains("myLogin.aspx"))
    {
        if (HttpContext.Current.Session["encryptedUserId"] == null)
        {


    HttpContext.Current.Response.Redirect("../Modulenames/mySessionExpired.aspx", false);
        }
    }
}

}

一切正常,唯一的问题是它在我的面包屑在页面中不起作用的 URL 中添加了某种加密。网址转换如下:

://thewebsite/Project/ (S(jnd4o5ljdgs0vq1zd4niby4a)) /Pages/mySessionExpired.aspx

不知道为什么要添加这段文字...请帮助

——阿图

4

0 回答 0