Why is ASP.NET MVC ignoring my trailing slash?

后端 未结 2 1946
感动是毒
感动是毒 2021-01-12 05:16

Consider the following route:

    routes.MapRoute(
        \"Service\", // Route name
        \"service/\", // URL with parameters
        new {controller =          


        
相关标签:
2条回答
  • 2021-01-12 05:57

    Legenden - there is no immediate solution to the problem. You may have run across Jason Young's blog post about the issue, which is very informative. Scott Hanselmann posted a reply to it here, basically stating that he didn't think it was a big deal, and if it is, you can leverage the new IIS7 rewrite module to solve it.

    Ultimately though, you might want to look at a solution that was posted by murad on a similar question on StackOverflow: Trailing slash on an ASP.NET MVC route

    0 讨论(0)
  • 2021-01-12 06:07

    In your page load event add:

    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
    
    0 讨论(0)
提交回复
热议问题