I want to route that to the following path in my browser:
http://localhost/Reports/Tickets
How can i do that?
I try this:
routes.MapRoute( "Tickets",// Route name "Areas/Management/Views/Ticket/Report.aspx",// Original URL new{ controller ="Reports", action ="Tickets"}// New URL );
Is report.aspx an mvc view or a webforms page? (the reason I ask is because the file is report.aspx and many report pages end up being webforms pages).
For an mvc view that route is incorrect, the second paramter should be what you expect to see on the screen. ie should be "/Reports/Tickets".
In your global asax, you can put this route. Assuming a controller called Ticket, and an action method named Report in the Management area.
routes.MapRoute(
"Tickets", // Route name
"Reports/Tickets", // URL with parameters
new { controller = "Ticket", action = "Report", area = "Management" ,id = UrlParameter.Optional } // Parameter defaults
);
You cannot use the routing engine to route to a webforms page in an mvc page application. Also you can't have a webforms page in the Views folder, that is because views has it's own web.config with special settings for mvc.
Create a folder on the root of your webapplication called "webforms" and just put all webforms pages in there, then just link to them manually "/webforms/report.aspx" instead of going through the routing engine.
Yes, your outgoing routes are now generating in correctly. You have to be very careful when mixing mvc with webforms. You need to add the following class to your project:
public class MyCustomConstaint : IRouteConstraint{
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection){
return routeDirection == RouteDirection.IncomingRequest;
}
}
Then in your global.asax, change your route to the following:
routes.MapPageRoute("Tickets", "Reports/Tickets", "~/WebForms/Reports/Tickets.aspx", true, null, new RouteValueDictionary { { "outgoing", new MyCustomConstaint() } });
Vecthor
Member
19 Points
27 Posts
How to route a .aspx page in asp.net mvc 3 project?
Apr 16, 2012 02:56 PM|LINK
I have a .aspx page in the following path:
I want to route that to the following path in my browser:
How can i do that?
I try this:
But i got the
error.What i'm doing wrong?
Obs: I put that before the
route.Webforms mvc Routing
BrockAllen
All-Star
28084 Points
4997 Posts
MVP
Re: How to route a .aspx page in asp.net mvc 3 project?
Apr 16, 2012 03:19 PM|LINK
I think you need to read over the MVC tutorials.
Webforms mvc Routing
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
CodeHobo
All-Star
18669 Points
2648 Posts
Re: How to route a .aspx page in asp.net mvc 3 project?
Apr 16, 2012 04:03 PM|LINK
Is report.aspx an mvc view or a webforms page? (the reason I ask is because the file is report.aspx and many report pages end up being webforms pages).
For an mvc view that route is incorrect, the second paramter should be what you expect to see on the screen. ie should be "/Reports/Tickets".
In your global asax, you can put this route. Assuming a controller called Ticket, and an action method named Report in the Management area.
routes.MapRoute( "Tickets", // Route name "Reports/Tickets", // URL with parameters new { controller = "Ticket", action = "Report", area = "Management" ,id = UrlParameter.Optional } // Parameter defaults );Webforms mvc Routing
Blog | Twitter : @Hattan
Vecthor
Member
19 Points
27 Posts
Re: How to route a .aspx page in asp.net mvc 3 project?
Apr 16, 2012 04:33 PM|LINK
@CodeHobo, is a webforms page.
Webforms mvc Routing
CodeHobo
All-Star
18669 Points
2648 Posts
Re: How to route a .aspx page in asp.net mvc 3 project?
Apr 16, 2012 04:41 PM|LINK
You cannot use the routing engine to route to a webforms page in an mvc page application. Also you can't have a webforms page in the Views folder, that is because views has it's own web.config with special settings for mvc.
Create a folder on the root of your webapplication called "webforms" and just put all webforms pages in there, then just link to them manually "/webforms/report.aspx" instead of going through the routing engine.
Blog | Twitter : @Hattan
Vecthor
Member
19 Points
27 Posts
Re: How to route a .aspx page in asp.net mvc 3 project?
Apr 16, 2012 04:51 PM|LINK
The problem is that. I don't want to use the .aspx at the end.
I try it: http://stackoverflow.com/questions/10178276/after-add-mappageroute-to-an-asp-net-mvc-project-the-site-stops-to-enter-in-hom
Do you know why i got this problem?
CodeHobo
All-Star
18669 Points
2648 Posts
Re: How to route a .aspx page in asp.net mvc 3 project?
Apr 16, 2012 05:16 PM|LINK
Yes, your outgoing routes are now generating in correctly. You have to be very careful when mixing mvc with webforms. You need to add the following class to your project:
public class MyCustomConstaint : IRouteConstraint{ public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection){ return routeDirection == RouteDirection.IncomingRequest; } }Then in your global.asax, change your route to the following:
routes.MapPageRoute("Tickets", "Reports/Tickets", "~/WebForms/Reports/Tickets.aspx", true, null, new RouteValueDictionary { { "outgoing", new MyCustomConstaint() } });Blog | Twitter : @Hattan