Не добавляйте AuthorizationAttribute в свой метод действия, когда вам, например, не требуется.
Мой пользовательский атрибут
public class AuthorizationFilterAttribute : AuthorizeAttribute
{
// Some code...
}
Мой контроллер
public class UserController : BaseController, IDisposable
{
[AuthorizationFilterAttribute]
public ActionResult UserList()
{
// Authorize attribute will call when this action is executed
}
public ActionResult AddUser()
{
// Authorize attribute will not call when this action is executed
}
}
Я надеюсь, вы поняли, что я пытаюсь вам сказать.
============================ Обновленный ответ ============== ==================
Создайте еще один атрибут, как показано ниже.
public sealed class AnonymousAttribute : Attribute { }
Пожалуйста, укажите ниже код вашего метода OnAuthorization.
public override void OnAuthorization(AuthorizationContext filterContext)
{
bool checkForAuthorization =
filterContext.ActionDescriptor.IsDefined(typeof(AnonymousAttribute), true) ||
filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AnonymousAttribute), true);
if (!skipAuthorization)
{
base.OnAuthorization(filterContext);
}
}