【问题标题】:Auth Cookie expiration in .Net.Net 中的 Auth Cookie 过期
【发布时间】:2010-01-13 01:19:38
【问题描述】:

我正在开发一个使用 ASP.Net 的表单身份验证的应用程序。客户端还对服务器(前端的 ExtJS 组件)进行 RESTfull 调用。

我们正在为服务调用使用自定义 HttpHandler。

我的问题是,无论何时身份验证 cookie 过期,我的 HttpHandler 的 ProcessRequest 方法都不会被调用,以便我检查 cookie 的缺失并重定向用户以再次登录。

例如,用户打开页面,然后在 20 分钟后返回并点击异步加载的下拉菜单。该应用程序只是挂起,永远不会到达我的处理程序。

有什么想法吗?

【问题讨论】:

    标签: asp.net asp.net-ajax cookies extjs rest


    【解决方案1】:

    强烈建议阅读这篇 MSDN 杂志文章中标题为“管道事件模型”的部分:Securely Implement Request Processing, Filtering, and Content Redirection with HTTP Pipelines in ASP.NET

    简而言之,在将请求移交给 HttpHandler 中的ProcessRequest() 之前,身份验证已经执行完毕。如果您需要处理这些情况,则需要挂钩管道事件(例如 BeginRequest 或 Authenticate Request)并添加您自己的处理程序,如下所示:

    public class EnableWebServicesModule : 
                   IHttpModule
      {
    
        public void Init(HttpApplication app)
        {
          // register event handler
          app.BeginRequest +=  new EventHandler(this.OnBeginRequest);
        }
    
        public void OnBeginRequest(object obj, EventArgs ea)
        {
          // Check if security works here by looking for the cookie or
          // the user context.
    
        }
    
        ...
    }
    

    如需进一步阅读这个引人入胜且令人兴奋的话题,请check Rich Strahl's walkthrough: A low-level Look at the ASP.NET Architecture

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-14
      • 2015-03-23
      • 1970-01-01
      • 2021-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多