asp.net-mvcmodel-view-controllerportable-areas

How to use [Authorize] attribute in project which using MVC Portable Areas


My project using MVC Portable Areas, its contain 2 projects, one is the main, and the other is Account project. In AccountController, I use [Authorize] attribute to redirect user to Login page, but I always receive "You don't have permission to access this directory". Any solution for me?


Solution

  • Controller code:

    [Authorize]
    public partial class AccountController : Controller
    {
        [AllowAnonymous]
        public virtual ActionResult Login(string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;
            return View();
        }
    }
    

    Root Web.config:

    <authentication mode="Forms">
      <forms name=".FORM" loginUrl="area/account/login" protection="All" timeout="30" path="/"/>
    </authentication>
    

    It works without any problems in my project which using MVC Portable Areas.

    Also, make sure that [Authorize] attribute redirect to the correct page and correct action method