Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

c# - How to route a .aspx page in asp.net mvc 3 project?

I have a .aspx page in the following path:

Areas/Management/Views/Ticket/Report.aspx

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 
);

But i got the 404 error.

What i'm doing wrong?

Obs: I put that before the Default route.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you are trying to utilise web forms in a MVC project then I would move your .aspx out of the views folder, as it isn't really a view, so something like WebForms/Tickets/Report.aspx.

In web forms you map a route by calling the MapPageRoute method.

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapPageRoute("Tickets", "Reports/Tickets", "~/WebForms/Tickets/Report.aspx");
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });

You'll need to put that before the default MVC route.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...