Authorize attribute for ajax requests in asp.net MVC 4

后端 未结 2 805
别那么骄傲
别那么骄傲 2021-01-13 17:33

I have an action method and posting to it using ajax like this:

 $.ajax({
                    url: \"/GetSearchCriteria\",
                    type: \"GET\",         


        
相关标签:
2条回答
  • 2021-01-13 18:04

    Add AttributeUsage to your class:

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class,
                    AllowMultiple = false, Inherited = true)]
    public class AjaxAuthorizeAttribute : AuthorizeAttribute { ... }
    
    0 讨论(0)
  • 2021-01-13 18:15

    Please make sure you don't have a regular [Authorize] attribute on the Controller level.

    Because if so, your custom [AjaxAuthorize] won't be hit.

    0 讨论(0)
提交回复
热议问题