title: MVC Redirect after login
body: <p>I have an AccountController where users can login, and an area named Admin where users have to been autorized to see. When users log in with correct username and pw, it redirects to the same page again (<code>../Account/Login?ReturnUrl=%2FAdmin</code>)</p>
  
  <p>AccountController</p>
  
  <pre><code>public class AccountController : Controller
      {
          [AllowAnonymous]
          public ActionResult Login()
          {
              return View();
          }
          [HttpPost]
          [AllowAnonymous]
          [ValidateAntiForgeryToken]
          public ActionResult Login(LoginModel model, string returnUrl)
          {
              if (ModelState.IsValid)
              {
                  if (model.Username == "User" &amp;&amp; model.Password == "Pa$$W0rd")
                  {
                      FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
                      if (!string.IsNullOrWhiteSpace(returnUrl))
                      {
                          return Redirect(returnUrl);
                      }
                      return RedirectToAction("Index", "Admin", new { area = "Admin"});
                  }
                  ModelState.AddModelError("", "Brukernavn og/eller passord er feil");
              }
              return View();
          }
  }
  </code></pre>
  
  <p>AdminController in area Admin</p>
  
  <pre><code>[Authorize]
  public class AdminController : HimmelhoytControllerBase
  {
          public ActionResult Index()
          {
              return View();
          }
  }
  </code></pre>
  
  <p>View Login</p>
  
  <pre><code>@model Himmelhoyt.Models.AccountModels.LoginModel
  @{
      ViewBag.Title = "Logg inn";
  }
      @using (Html.BeginForm("Login", "Account", FormMethod.Post, new { @class = "form-signin" }))
      {
          &lt; text&gt;
              @Html.AntiForgeryToken()
  
              @Html.LabelFor(m =&gt; m.Username, new { @class = "sr-only" }) @Html.EditorFor(m =&gt; m.Username, new { htmlAttributes = new { @class = "form-control", placeholder = "Brukernavn", autofocus = "autofocus" } })
              @Html.ValidationMessageFor(m =&gt; m.Username, "", new { @class = "bg-danger validationMessage" })
  
              @Html.LabelFor(m =&gt; m.Password, new { @class = "sr-only" }) @Html.EditorFor(m =&gt; m.Password, new { htmlAttributes = new { @class = "form-control", placeholder = "Passord", type = "password" } })
              @Html.ValidationMessageFor(m =&gt; m.Password, "", new { @class = "bg-danger validationMessage" })
              &lt;br/&gt;
              @Html.EditorFor(x =&gt; x.RememberMe@*, new { htmlAttributes = new { @class = "checkbox" } }*@) @Html.LabelFor(m =&gt; m.RememberMe)
              @Html.ValidationMessageFor(m =&gt; m.RememberMe)
              &lt;br /&gt;
              @Html.Submit("Logg på", new { @class = "btn btn-lg btn-primary btn-block" })
  
              @Html.ValidationSummary(true)
          &lt;/text&gt;
      }
  </code></pre>
  
  <p>In the Account-controller, <code>return RedirectToAction("Index", "Admin", new { area = "Admin" });</code> is executed, but as I said, it only redirects to the same page.</p>
  
  <p><strong>EDITED</strong>
  Web.config</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;configSections&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
    &lt;/configSections&gt;
    &lt;connectionStrings&gt;
      &lt;add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-Himmelhoyt-20140831071527.mdf;Initial Catalog=aspnet-Himmelhoyt-20140831071527;Integrated Security=True" providerName="System.Data.SqlClient" /&gt;
      &lt;add name="HimmelhoytDb" connectionString="data source=(localdb)\v11.0;initial catalog=Himmelhoyt;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" /&gt;
    &lt;/connectionStrings&gt;
    &lt;appSettings&gt;
      &lt;add key="webpages:Version" value="3.0.0.0" /&gt;
      &lt;add key="webpages:Enabled" value="false" /&gt;
      &lt;add key="ClientValidationEnabled" value="true" /&gt;
      &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;!--&lt;authentication mode="None" /&gt;--&gt;
      &lt;authentication mode="Forms"&gt;
        &lt;forms loginUrl="/Account/Login" /&gt;
      &lt;/authentication&gt;
      &lt;compilation debug="true" targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5" /&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;modules&gt;
        &lt;remove name="FormsAuthentication" /&gt;
      &lt;/modules&gt;
    &lt;/system.webServer&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
  &lt;/configuration&gt;
  </code></pre>