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

Custom AuthorizeAttribute - ASP.NET MVC

RSS
Modified on Tue, Feb 19, 2013, 10:14 AM by Administrator Categorized as ASP·NET MVC
using System.Web.Mvc;

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

    public override void OnAuthorization(AuthorizationContext filterContext)
    {
        _controllerTypeName = filterContext.Controller.GetType().FullName;

        // The following line calls the AuthorizeCore method, below.
        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-2018, Patrick Jasinski.