Friendly URLs for ASP.NET

后端 未结 6 1095
旧时难觅i
旧时难觅i 2020-11-30 19:48

Python frameworks always provide ways to handle URLs that convey the data of the request in an elegant way, like for example http://somewhere.overtherainbow.com/userid/12342

6条回答
  •  天涯浪人
    2020-11-30 20:30

    I've developed an open source NuGet library for this problem which implicitly converts EveryMvc/Url to every-mvc/url.

    Dashed urls are much more SEO friendly and easier to read. Lowercase URLs tend to create less problems. (More on my blog post)

    NuGet Package: https://www.nuget.org/packages/LowercaseDashedRoute/

    To install it, simply open the NuGet window in the Visual Studio by right clicking the Project and selecting NuGet Package Manager, and on the "Online" tab type "Lowercase Dashed Route", and it should pop up.

    Alternatively, you can run this code in the Package Manager Console:

    Install-Package LowercaseDashedRoute

    After that you should open App_Start/RouteConfig.cs and comment out existing route.MapRoute(...) call and add this instead:

    routes.Add(new LowercaseDashedRoute("{controller}/{action}/{id}",
      new RouteValueDictionary(
        new { controller = "Home", action = "Index", id = UrlParameter.Optional }),
        new DashedRouteHandler()
      )
    );
    

    That's it. All the urls are lowercase, dashed, and converted implicitly without you doing anything more.

    Open Source Project Url: https://github.com/AtaS/lowercase-dashed-route

提交回复
热议问题