考虑以下路线:

    routes.MapRoute(
        "Service", // Route name
        "service/", // URL with parameters
        new {controller = "CustomerService", action = "Index"} // Parameter defaults
        );

使用 Url.Action(" Service"," CustomerService")生成 / service 的网址,而不是预期的 / service /

有没有办法让它工作,或者我是否必须求助于实现我自己的路由派生自 RouteBase

有帮助吗?

解决方案

Legenden - 没有立即解决问题的办法。您可能遇到过 Jason Young的博文关于这个问题,这是非常翔实的。 Scott Hanselmann在这里发布了回复,基本上说明他并不认为这是一个大问题,如果是,你可以利用新的IIS7重写模块来解决它。

最终,你可能想看一下murad在StackOverflow上的一个类似问题上发布的解决方案: ASP.NET MVC路由上的尾部斜杠

其他提示

在您的页面加载事件中添加:

Dim rawUrl As String = HttpContext.Current.ApplicationInstance.Request.RawUrl
If Not rawUrl.EndsWith("/") Then
    HttpContext.Current.ApplicationInstance.Response.RedirectPermanent(String.Format("~{0}/", rawUrl))
End If
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top