title: ASP.Net MVC @Url.Action() routing to the wrong controller
body: <p>I'm newbie to MVC. I could integrate MVC 5.2 to my existing web forms Visual Studio 2012 Update 4 project. I created my first controller and all worked as expected. Even I was able to  leverage the windows forms authentication from my existing project when accessing the MVC view. But when created my second controller it began messing up.</p>
  
  <p>It is my route mapping:</p>
  
  <pre><code>public static class RouteConfig
  {
      public static void RegisterRoutes(RouteCollection routes)
      {
          routes.EnableFriendlyUrls();
  
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
          routes.MapRoute(
              name: "Default",
              url: "{controller}/{action}/{id}",
              defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
          );
      }
  }
  </code></pre>
  
  <p>I have two controllers both located in ~/Controllers. My first controller is:</p>
  
  <pre><code>public class HomeController : Controller
  {
      //
      // GET: /Home/
      public ActionResult Index()
      {
          //return View();
          return Redirect("~/Default.aspx");
      }
  
      public ActionResult CloseSession()
      {
          return Redirect("http://www.yahoo.com");
      }
  }
  </code></pre>
  
  <p>The second controller:</p>
  
  <pre><code>public class CajaWebController : Controller
  {
      //
      // GET: /CajaWeb/
      public ActionResult Index()
      {
          return View();
      }
  
      public ActionResult CloseSession()
      {
          return Redirect("http://www.cnn.com");
      }
  }
  </code></pre>
  
  <p>I don't know is it relevant to the problem but I'll include how the MVC view is reached. My VS2012 start url is </p>
  
  <pre><code>http://localhost/Fortia/CajaWeb. 
  </code></pre>
  
  <p>Fortia is my app name. Because I declared Web Forms authentication and </p>
  
  <pre><code>&lt;location path="CajaWeb"&gt;
    &lt;system.web&gt;
      &lt;authorization&gt;
        &lt;allow roles="Fortia" /&gt;
        &lt;deny users="*" /&gt;
      &lt;/authorization&gt;
    &lt;/system.web&gt;
  &lt;/location&gt;
  </code></pre>
  
  <p>when starting to debug the old WebForms app authentication mechanism is called, the old WebForms login page invoked and after a successful login finally my CajaWebController, Index() action is called. Before creating CajaWebController it was the HomeController who was called, but I assume MVC now deduces the correct controller is CajaWeb because of the  targeted url being </p>
  
  <pre><code>http://localhost/Fortia/CajaWeb. 
  </code></pre>
  
  <p>The invoked view contains the following code:</p>
  
  <pre><code>&lt;a href='@Url.Action("CloseSession", "CajaWeb")'&gt;Close session&lt;/a&gt;
  </code></pre>
  
  <p>The problem is when clicking the generated link the MVC calls HomeController.Index() action despite I explicitly set CajaWebController.CloseSession() in the @Url.Action...</p>
  
  <p>I looked at the generated link and it looks wrong:</p>
  
  <pre><code>&lt;a href='/Fortia/__FriendlyUrls_SwitchView?action=CloseSession&amp;amp;controller=CajaWeb'&gt;
  </code></pre>
  
  <p>it encoded the parameter separator &amp; into &amp; But anyway I tried handcoding the href as </p>
  
  <pre><code>http://localhost/Fortia/__FriendlyUrls_SwitchView?action=CloseSession&amp;controller=CajaWeb 
  </code></pre>
  
  <p>but the result was the same.</p>
  
  <p>What is wrong?</p>