title: ASP.NET MVC Areas - ActionLink and RedirectToAction
body: <p>While using Areas in ASP.NET MVC 3 project, I stumbled across this problem to do with ActionLink and RedirectToAction method.</p>
  
  <p>I added the following code in the AccountController which is at the Root level ...</p>
  
  <pre><code>[HttpPost]
  public ActionResult LogOn(LogOnModel model, string returnUrl)
  {
      if (ModelState.IsValid)
      {
          if (Membership.ValidateUser(model.UserName, model.Password))
          {
              FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
              if (Url.IsLocalUrl(returnUrl) &amp;&amp; returnUrl.Length &gt; 1 &amp;&amp; returnUrl.StartsWith("/")
                  &amp;&amp; !returnUrl.StartsWith("//") &amp;&amp; !returnUrl.StartsWith("/\\"))
              {
                  return Redirect(returnUrl);
              }
              else
              {
                  if (Roles.Provider.IsUserInRole(model.UserName, "Admin"))
                  {
                      return RedirectToAction("Index", "Admin", new { area = "Admin" });
                  }
                  else
                  {
                      return RedirectToAction("Index", "Home");
                  }                        
              }
          }
          else
          {
              ModelState.AddModelError("", "The user name or password provided is incorrect.");
          }
      }
  </code></pre>
  
  <p>Based on the Role which the currently logging in User belongs to, I redirect to the appropriate area. It's working correctly up to this point.</p>
  
  <p>The Admin Area looks as follows ...</p>
  
  <p><img src="https://i.stack.imgur.com/arzBH.png" alt="enter image description here"></p>
  
  <p>In this area, I had copied the <strong>_ViewStart.cshtml</strong> from the root.</p>
  
  <p>The links for <strong>Log Off</strong>, <strong>About</strong>, <strong>Home</strong> etc dont work as the route which they point to doesn't exist.</p>
  
  <p><img src="https://i.stack.imgur.com/JSYdh.png" alt="enter image description here"></p>
  
  <p>I don't want to create another Account, or Home controller in the Areas folder. I would like to use the one in the root.</p>
  
  <p>Following the advice received, on changing the <strong>_LogOnPartial.cshtml</strong> code as shown ...</p>
  
  <pre><code>@if(Request.IsAuthenticated) {
      &lt;text&gt;Welcome &lt;strong&gt;@User.Identity.Name&lt;/strong&gt;!
      [ @Html.ActionLink("Log Off", "LogOff", "Account", new { area = "" }) ]&lt;/text&gt;
  }
  else {
      @:[ @Html.ActionLink("Log On", "LogOn", "Account", new { area = "" }) ]
  }
  </code></pre>
  
  <p>produces the following URL ...</p>
  
  <p><img src="https://i.stack.imgur.com/6AkF1.png" alt="enter image description here"></p>
  
  <p>which is still not right.</p>