I am new to MVC. I could integrate MVC 5.2 into my existing web forms Visual Studio 2012 Update 4. I created my first controller and everything worked as expected. Even when I was accessing MVC viewing, I was able to use Windows Form Authentication from my existing project. But when my second controller was created, it started to go bad.
This is my route mapping:
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 } ); } }
I have two controllers located in ~ / controllers. My first controller:
public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { //return View(); return Redirect("~/Default.aspx"); } public ActionResult CloseSession() { return Redirect("http://www.yahoo.com"); } }
Second controller:
public class CajaWebController : Controller { // // GET: /CajaWeb/ public ActionResult Index() { return View(); } public ActionResult CloseSession() { return Redirect("http://www.cnn.com"); } }
I do not know if this relates to the problem, but I will tell you how the MVC representation is achieved. My VS2012 Launch URL
http:
Fortia is my application name. Since I declared web form validation and
<location path="CajaWeb"> <system.web> <authorization> <allow roles="Fortia" /> <deny users="*" /> </authorization> </system.web> </location>
when the debugging of the old WebForms application authentication mechanism starts, the old WebForms login page is called and after a successful login, finally my CajaWebController, Index () action is called. Before creating the CajaWebController, the HomeController was called, but I assume that MVC now displays the correct CajaWeb controller due to the destination URL
http:
The called view contains the following code:
<a href='@Url.Action("CloseSession", "CajaWeb")'>Close session</a>
The problem is that when I click on the generated link, MVC calls the HomeController.Index () action, despite the fact that I explicitly set CajaWebController.CloseSession () to @ Url.Action ...
I looked at the generated link and it looks wrong:
<a href='/Fortia/__FriendlyUrls_SwitchView?action=CloseSession&controller=CajaWeb'>
he encoded the parameter separator and entered. But anyway I tried handcoding href like
http:
but the result was the same.
What's wrong?