Obs: to reproduce this error, create a new asp.net mvc project as internet app, after create the `Tickets` webforms page inside a `/WebForms/Reports` folder, and register the new route. Run the project (probably you're logged), so now logoff and you will be redirected to `http://localhost:35874/Reports/Tickets?action=LogOff&controller=Account`, so why?
I answered this in your other thread, but you need to add a route containt to the webforms route to ensure that it only catches on incoming routes, not outgoing route generation.
Add the following class to your project (either in a new file or the bottom of global.asax.cs):
public class MyCustomConstaint : IRouteConstraint{
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection){
return routeDirection == RouteDirection.IncomingRequest;
}
}
Then change the Tickets route to the following:
routes.MapPageRoute(
"Tickets",
"Reports/Tickets",
"~/WebForms/Reports/Tickets.aspx",
true, null,
new RouteValueDictionary { { "outgoing", new MyCustomConstaint() } }
);
If you are using Forms Authentication as you mentioned, are you using something such as an [Authorize] attribute on a specific method or controller that may be causing the redirect.
If that isn't the issue - you may want to look into adding a constraint to your routes (Adding Route Constraints).
No problem, I'm not sure about the internals. But the routing engine is confusing an MVC route with a webforms route, so when you call @Html.ActionLink, instead of selecting the correct mvc route, it was picking the webforms route. By specificy a route contraint
you ensure that the webforms route is only used for handling incoming requests and not generating links. That's the behavior you want, as you don't want @Html.ActionLink to generate a link to a webforms page.
Vecthor
Member
19 Points
27 Posts
After add MapPageRoute to an asp.net mvc project, the site stops to enter in Home Controller
Apr 16, 2012 05:11 PM|LINK
I'm trying to route a .aspx (webforms page) in my asp.net mvc project. I register the page in global.asax:
The problem is, after i add the second line, the site stops to enter in my Home Controller (Index Action) and is redirecting to: http://localhost:37538/Reports/Tickets?action=Index&controller=Login%22 always that i run the project.
Project Details:
Obs: to reproduce this error, create a new asp.net mvc project as internet app, after create the `Tickets` webforms page inside a `/WebForms/Reports` folder, and register the new route. Run the project (probably you're logged), so now logoff and you will be redirected to `http://localhost:35874/Reports/Tickets?action=LogOff&controller=Account`, so why?
CodeHobo
All-Star
18647 Points
2647 Posts
Re: After add MapPageRoute to an asp.net mvc project, the site stops to enter in Home Controller
Apr 16, 2012 05:22 PM|LINK
I answered this in your other thread, but you need to add a route containt to the webforms route to ensure that it only catches on incoming routes, not outgoing route generation.
Add the following class to your project (either in a new file or the bottom of global.asax.cs):
public class MyCustomConstaint : IRouteConstraint{ public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection){ return routeDirection == RouteDirection.IncomingRequest; } }Then change the Tickets route to the following:
routes.MapPageRoute( "Tickets", "Reports/Tickets", "~/WebForms/Reports/Tickets.aspx", true, null, new RouteValueDictionary { { "outgoing", new MyCustomConstaint() } } );Blog | Twitter : @Hattan
Rion William...
All-Star
26445 Points
4389 Posts
Re: After add MapPageRoute to an asp.net mvc project, the site stops to enter in Home Controller
Apr 16, 2012 05:22 PM|LINK
If you are using Forms Authentication as you mentioned, are you using something such as an [Authorize] attribute on a specific method or controller that may be causing the redirect.
If that isn't the issue - you may want to look into adding a constraint to your routes (Adding Route Constraints).
Vecthor
Member
19 Points
27 Posts
Re: After add MapPageRoute to an asp.net mvc project, the site stops to enter in Home Controller
Apr 16, 2012 05:29 PM|LINK
@CodeHobo, if not asking so much, can you explain me why this happens? Or give me some link to understand this problem?
CodeHobo
All-Star
18647 Points
2647 Posts
Re: After add MapPageRoute to an asp.net mvc project, the site stops to enter in Home Controller
Apr 16, 2012 05:47 PM|LINK
No problem, I'm not sure about the internals. But the routing engine is confusing an MVC route with a webforms route, so when you call @Html.ActionLink, instead of selecting the correct mvc route, it was picking the webforms route. By specificy a route contraint you ensure that the webforms route is only used for handling incoming requests and not generating links. That's the behavior you want, as you don't want @Html.ActionLink to generate a link to a webforms page.
Blog | Twitter : @Hattan
Vecthor
Member
19 Points
27 Posts
Re: After add MapPageRoute to an asp.net mvc project, the site stops to enter in Home Controller
Apr 16, 2012 06:04 PM|LINK
Thank you! =D