开发者

How to create the custom authorize filter?

开发者 https://www.devze.com 2023-01-08 13:52 出处:网络
How do Icreate my own authorize filter for the asp.net mvc controller? I want to secure the controller actions that are releated to xo, what do I need to do开发者_StackOverflow社区 for that?Simply ex

How do I create my own authorize filter for the asp.net mvc controller?

I want to secure the controller actions that are releated to xo, what do I need to do开发者_StackOverflow社区 for that?


Simply extend AuthorizeAttribute and override AuthorizeCore, add in your own logic and return true or false.

public class CustomAuthorizeAttribute : AuthorizeAttribute
{
    protected override bool AuthorizeCore(HttpContextBase httpContext)
    {
        var defaultResult = base.AuthorizeCore(httpContext);

        // custom logic

        return true; // or false
    }
}
0

精彩评论

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