Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Page History: Custom AuthorizeAttribute - ASP.NET MVC

Compare Page Revisions



« Older Revision - Back to Page History - Current Revision


Page Revision: Tue, Feb 19, 2013, 10:04 AM


using System.Web.Mvc;

public class AppAuthorizeAttribute : AuthorizeAttribute
{
    private string _controllerTypeName = string.Empty;

    public override void OnAuthorization(AuthorizationContext filterContext)
    {
        _controllerTypeName = filterContext.Controller.GetType().FullName;
        base.OnAuthorization(filterContext);
    }
    /// <returns>True if the user is authorized; false otherwise.</returns>
    protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext)
    {
        var userLoginName = httpContext.User.Identity.Name;
        // TODO: write specialized authorization code here based on _controllerTypeName and userLoginName
        return base.AuthorizeCore(httpContext);
    }
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2020, Patrick Jasinski.