相关疑难解决方法(0)

操作过滤器执行顺序

我创建了两个实现的类AuthorizeAttribute.

一个是全局使用的,我将它设置在Global.asax.cs上:

filters.Add(new FirstAuthorizeAttribute() { Order = 0 });
Run Code Online (Sandbox Code Playgroud)

另一个被调用SecondAuthorizeAttribute,它只在一些动作方法中使用,我在我想要的方法中使用它作为属性.

    [HttpGet]
    [SecondAuthorize]
    public ActionResult LogOut()
    {
        FormsAuthentication.SignOut();
        Session.Clear();
        Session.Abandon();
        return Redirect(Url.Content("~/"));
    }
Run Code Online (Sandbox Code Playgroud)

问题是SecondAuthorizeAttribute始终执行之前FirstAuthorizeAttribute,我需要先执行此操作.订单没有帮助,我怎么能这样做?

asp.net-mvc authorize-attribute action-filter asp.net-mvc-3

19
推荐指数
2
解决办法
2万
查看次数

当`PostAuthenticateRequest`被执行时?

这是我的Global.asax.cs档案:

public class MvcApplication : System.Web.HttpApplication
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        ...
    }

    protected void Application_Start()
    {
        this.PostAuthenticateRequest += new EventHandler(MvcApplication_PostAuthenticateRequest);
    }

    // This method never called by requests...
    protected void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e)
    {
        HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

        if (authCookie != null)
        {
            FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
            var identity = new GenericIdentity(authTicket.Name, "Forms");
            var principal = new GenericPrincipal(identity, new string[] { });
            Context.User = principal;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

什么时候PostAuthenticateRequest执行?

.net c# asp.net asp.net-mvc-2

13
推荐指数
2
解决办法
2万
查看次数

全局过滤器MVC 4的执行顺序是什么

我在我的MVC 4应用程序中有2个全局操作过滤器,我使用RegisterGlobalFilters在Filter.config文件中注册.我需要它们按特定顺序执行.

我知道如何为Controller特定的过滤器指定顺序,但是如何为全局过滤器指定顺序和范围?是按照他们注册的顺序?

action-filter asp.net-mvc-4

5
推荐指数
2
解决办法
4540
查看次数