2016-05-16 34 views
1

今天我有一個真正糟糕的WebForms日!WebForms表單身份驗證:成功登錄並重定向後Request.IsAuthenticated = false

我有一個使用Forms Authentication的成熟WebForms Web應用程序。由於某種未知的原因,我的應用程序已經開始顯示Request.IsAuthenticated(在Global.asaxApplication_BeginRequest功能),儘管進入登錄頁面,登錄成功,並呼籲FormsAuthentication.RedirectFromLoginPage()

我只是不能解決出了什麼問題。這是我所做的檢查。我希望有人可能會指出一些我沒有到過這裏:

  1. web.config認證部分如下:

    <authentication mode="Forms"> 
        <forms loginUrl="~/Login" timeout="120" cookieless="UseCookies" defaultUrl="~/ExitPoint.aspx?Page=Home" /> 
    </authentication> 
    
  2. web.config授權部分如下:

    <authorization> 
        <deny users="?" /> 
        <allow users="*" /> 
    </authorization> 
    
  3. 對於如登錄/註銷頁面我有:

    <location path="Login"> 
        <system.web> 
         <authorization> 
          <allow users="*" /> 
         </authorization> 
        </system.web> 
    </location> 
    
  4. 當登錄時,我有了突破,並逐步完成了身份驗證過程。這結束了與:

    FormsAuthentication.RedirectFromLoginPage(userID, createPersistentCookie: true); 
    // Includes call to SetAuthCookie() 
    

,其中用戶ID是 「768」 字符串值。

  • 加密的會話cookie出現在瀏覽器上的下一個請求:

    Name=.ASPXAUTH 
    Value=FFC592..... 
    Expires=2016-05-16T15:41:58.817Z (basically "now"+1 hour) 
    Path=/ 
    Domain=localhost 
    HTTP=Yes 
    Secure=(blank i.e. No) 
    
  • 登錄在Global.asaxApplication_BeginRequest()方法Request.IsAuthenticated值輸出 「假」(布爾)

  • 我還需要檢查什麼以查看可能會發生什麼錯誤? THanks

    回答

    1

    我認爲這正是預期的。在webforms請求流水線中,AuthenticateRequest事件在BeginRequest事件之後引發,因此請求在BeginRequest事件中尚未通過身份驗證纔有意義。

    關於流水線的描述參見(例如)here。或者只是谷歌爲asp net webforms request pipeline,你會發現很多鏈接...

    從頁部分副本我掛:

    1. 驗證請求,該檢查由瀏覽器發送的信息,並確定它是否包含潛在的惡意標記。有關更多信息,請參閱驗證請求和腳本利用漏洞概述。
    2. 如果在Web.config文件的UrlMappingsSection部分中配置了任何URL,請執行URL映射。
    3. 引發BeginRequest事件。
    4. 引發AuthenticateRequest事件。
    5. 提高PostAuthenticateRequest事件。
    6. 提高AuthorizeRequest事件。
    7. 引發PostAuthorizeRequest事件。
    8. ...
    +0

    謝謝。我可以發誓'Request.IsAuthenticated'在'Begin_Request'處理程序中顯示爲true(一旦登錄),但是根據您提供的證據和我得到的實際效果,我一定是在欺騙自己!謝謝。 –

    相關問題