Translate

Tuesday 24 January 2017

Is it possible to disable authorization on one action in an MVC controller?

You can add [Authorize] To the controller class, and then add [AllowAnonymous] to the single action you don't want to be authorized. Example:
[Authorize]
    public class AccountController : Controller
    {
        public ActionResult Profile()
        {
            return View();
        }

        [AllowAnonymous]
        public ActionResult Login()
        {
            return View();
        }
    }

No comments:

Post a Comment