开发者

.NET MVC - Windows Integrated Authentication + Authorization

My question is similar to many more that have been asked.

I have a simple app hosted internal to my company (accessed on the intranet). It is an MVC app with integrated Windows Authentication.

I have all the code to authorize a user against Active Directory. How do I implement this in the client (web.config + globa开发者_运维问答l.asax etc)?

Do I use the global.asax event methods available? I can authorize every page request or setup sessions but if someone has a working example of how to route to custom pages without triggering an infinite loop that would be great!

Alternatively is there something in MVC that makes this all much simpler that I am missing? I don't believe the [Authorize] attribute meets this exact requirement.

I have tried this to no avail:

    /// <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");

        } 
    }

Thanks in advance


AuthorizeFilterAttribute or any customization thereof is exactly what i was looking.. thanks me!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜