简体   繁体   English

ASP.Net MVC 2 路由

[英]ASP.Net MVC 2 Routing

I need a feedback on a routing-related issue I've found while publishing an ASP.NET MVC 2 application.我需要关于发布 ASP.NET MVC 2 应用程序时发现的路由相关问题的反馈。 In the global.asax file I defined the following routes:在 global.asax 文件中,我定义了以下路线:

// Thumbnails routing.
// Sample URL: resizer/resizeImage/200/200/Error/error.jpg
routes.MapRoute("Resizer","Resizer/{action}/{width}/{height}/{folder}/{file}",
new  { controller = "Resizer", action = "ResizeImage", width = 100,height = 100,
folder = "Error", file = "error.jpg"
}   
);
// Default routing.
// Sample URL: /Home/Index
routes.MapRoute("Default",  "{controller}/{action}.aspx/{id}",
new { controller = "Home", action = "Index", id = (string)null }
);  

So, firstly I had to add.aspx for the default routing otherwise the hosting server (Aruba) does not perform properly routing... so first question: is there any other workaround to maintain normal routing (ie without adding.aspx)?所以,首先我必须为默认路由添加.aspx,否则托管服务器(Aruba)无法正确执行路由......所以第一个问题:是否有任何其他解决方法来维持正常路由(即不添加.aspx)?

The 'Resizer' route should allow to call a controller that should generate thumbnails images: It works locally but not when the web site is published. 'Resizer' 路由应该允许调用应该生成缩略图的 controller:它在本地工作,但在 web 站点发布时不能工作。

It seems that the route like 'resizer/resizeImage/200/200/Error/error.jpg' is not recognized.似乎无法识别像“resizer/resizeImage/200/200/Error/error.jpg”这样的路线。

How can I handle this issue?我该如何处理这个问题?

I don't think there is another way to avoid the.aspx instead the "normal" routing.我认为没有另一种方法可以避免使用 .aspx 而不是“正常”路由。 Any how I don't think it's a big deal.反正我觉得没什么大不了的。 I also think that in the code that you posted (I didn't try it) the routing is not correct: to add the aspx you should put the aspx after the controller name, in the default like in the resizer one.我还认为,在您发布的代码中(我没有尝试过),路由不正确:要添加 aspx,您应该将 aspx 放在 controller 名称之后,默认情况下就像在调整大小之一中一样。 Something like that:像这样的东西:

routes.MapRoute("Resizer", 
      "Resizer.aspx/{action}/{width}/{height}/{folder}/{file}", 
      new { controller = "Resizer", action = "ResizeImage", 
      width = 100, height = 100, folder = "Error", file = "error.jpg" });

/Stefano /斯蒂法诺

thanks for your reply.感谢您的回复。

I modified the routing adding '.aspx' to {action} also in the Resizer route.我也在 Resizer 路由中修改了将“.aspx”添加到 {action} 的路由。 Now it looks like:现在看起来像:

routes.MapRoute("Resizer", 
"Resizer/{action}.aspx/{width}/{height}/{folder}/{file}", 
new { controller = "Resizer", action = "ResizeImage", 
width = 100, height = 100, folder = "Error", file = "error" });

It seems to work properly, it is actually the only way to activate IIS routing.貌似可以正常工作,其实是激活IIS路由的唯一方法。

I also deleted the file extension (.jpg), just to avoid problem with the Dot character.我还删除了文件扩展名 (.jpg),只是为了避免点字符出现问题。

Marco马可

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM