能否访问会话状态从找到的解HTTP模块?,我能够从IHttpModule的访问会话状态。我用它来控制访问某些文件,所以在事件的人没有访问,我想他们重定向到登录页面。当我尝试做一个HttpContext.Current.Response.Redirect(页);它锁定的Web服务器了。所以,我的帖子获取请求状态函数看起来像这样...

 void Application_PostAcquireRequestState(object source, EventArgs e)
    {            
        HttpApplication app = (HttpApplication)source;

        MyHttpHandler resourceHttpHandler = HttpContext.Current.Handler as MyHttpHandler;

        if (resourceHttpHandler != null)
        {
            // set the original handler back
            HttpContext.Current.Handler = resourceHttpHandler.OriginalHandler;
        }

        HttpContext context = HttpContext.Current;
        string filePath = context.Request.FilePath;
        context.Trace.Write("HttpDownloadModule", "File path: " + filePath);

        Boolean hasAccess = true;

        if (filePath.Contains("content/downloads"))
        {
            //check to make sure a session has been established already....
            if (context.Session == null)
                hasAccess = false;

            SecurityBLL security = new SecurityBLL();
            string fileName = filePath.Split('/').Last();

            //check to see if a user is logged in
            if (!CitrixAccess.loggedin)
                hasAccess = false;

            //check access for download
            if (!security.checkSecurityByDownload(fileName))
                hasAccess = false;

            if (!hasAccess)
            {
                HttpContext.Current.Handler = resourceHttpHandler.OriginalHandler;
                HttpContext.Current.Response.Redirect("../../login.aspx");
            }
        }

    }

任何想法?感谢您的帮助!

有帮助吗?

解决方案

好了,我找到了一个解决方法......我感动我的hasAccess变量是全球性的,并增加了EndRequest处理程序。所以我检查在EndRequest hasAccess和做从那里重定向。

其他提示

我的回答包括 Arthurdent510公司回答,但我没有足够的声誉,他的回答简单哈哈评论。他的回答帮了我很多要弄清楚,我走了,但它不是相当完整的我。

把Response.Redirect的呼叫在EndRequest处理程序导致无限循环。我想这是因为Response.Redirect的原因EndRequest被调用。所以EndRequest正在反复调用永远。

要解决这个问题,我添加了一个私人布尔值,表明如果我已经呼吁重定向。如果我已经呼吁重定向,那么我不会再打电话的Response.Redirect。这就是我的EndRequest方法看起来像:

Private Sub Application_EndRequest(ByVal source As Object, ByVal e As EventArgs)
    If Not _blnHasAccess AndAlso Not _blnRedirected Then
        _blnRedirected = True
        HttpContext.Current.Response.Redirect("~/Error.aspx")
    End If
End Sub
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top