2010-07-26 85 views
0

我的問題類似於已經提出的許多問題。.NET MVC - Windows集成身份驗證+授權

我有一個簡單的應用程序託管在我的公司內部(在Intranet上訪問)。它是一個集成Windows身份驗證的MVC應用程序。

我擁有所有的代碼來授權用戶對Active Directory。我如何在客戶端實現這一點(web.config + global.asax等)?

我可以使用global.asax事件方法嗎?我可以授權每個頁面請求或安裝會話,但如果有人有一個如何路由到自定義頁面的工作示例,而不會觸發無限循環,那將非常棒!

或者是有什麼在MVC,使這一切都更簡單,我失蹤了?我不相信[Authorize]屬性滿足這個確切的要求。

我曾經嘗試這樣做無濟於事:提前

回答

0

AuthorizeFilterAttribute或其任何定製

/// <summary> 
    /// Handles the AuthenticateRequest event of the Application control. 
    /// </summary> 
    /// <param name="sender">The source of the event.</param> 
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> 
    protected void Application_AuthenticateRequest(object sender, EventArgs e) 
    { 
     bool isAuthorised = false; 

     if ((Request.IsAuthenticated) && (cookie == null)) 
      isAuthorised = AuthoriseUser(); 
    } 

    /// <summary> 
    /// Handles the EndRequest event of the Application control. 
    /// </summary> 
    /// <param name="sender">The source of the event.</param> 
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> 
    protected void Application_EndRequest(object sender, EventArgs e) 
    { 
     if ((Response.StatusCode == 401) && (Request.IsAuthenticated)) 
     { 
      Response.Redirect("/Shared/Denied"); 

     } 
    } 

謝謝正是我一直在尋找..感謝我!