Beispiel #1
0
    public override void OnAuthorization(AuthorizationContext filterContext)
    {
        //Here you will to figure out to
        //have to access your Context with some DependencyResolver
        //Exemple
        var _context = ISomeInterface.ReturnCurrentContext();

        var personLoggedIn = User.Identity.Name.Split('\\')[1];      // Intranet application.. so the domain name comes before the username hence the split

        if (_context.UserTable.Single(x => x.UserLogon == personLoggedIn).IsAdministrator == false)
        {
            filterContext.Result = new RedirectResult("~/PathToErrorView")
                                   //Or even
                                   filterContext.Result = new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest, "You don't have Access")
        }
        base.OnAuthorization(filterContext);
    }