About this Project

Tired of your MVC application generating mixed-case URLs like http://mysite.com/Home/About orhttp://mysite.com/Admin/Customers/List? Wouldn't http://mysite.com/home/about andhttp://mysite.com/admin/customers/list be a lot nicer? I think so too, so I wrote this little project to help make that work.

By default, ASP.NET MVC generates outgoing route URLs that preserve the casing of your controller and action names. Since controllers are classes and actions are methods, these outgoing URL segments will most likely be camel-cased, as that is the standard when naming these constructs. LowercaseRoutesMVC lets you very easily make ASP.NET MVC generate outgoing route URLs that are always lower-cased, without having to rename any of your controller classes or action methods. It includes support for MVC Areas as well. (If the generated outgoing URL contains a querystring, its casing will not be affected.)

There is also a separate beta version with support for lower-casing HTTP Routes generated by the ASP.NET Web API.

Usage Notes

Using this project is very easy. Once added as a reference in your web project, you need only make a minor change to the method calls in your RegisterRoutes method in Global.asax. If you are using Areas in your project, you will also make similar changes in the RegisterArea override(s) in your area registration classes

Step 1. - Install the library via Nuget

PM> Install-Package LowercaseRoutesMVC or via the NuGet management tools in Visual Studio.

If you need support for lower-casing HTTP Routes, install this version instead:

PM> Install-Package LowercaseRoutesMVC4

Step 2. - Remap Your Main Routes

Go to the RegisterRoutes method in Global.asax. Replace all the calls to MapRoute withMapRouteLowercase.

For example:

using LowercaseRoutesMVC
... public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRouteLowercase( // changed from routes.MapRoute
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}

  

Step 3. (if using Areas) - Remap Your Area Routes

Go to the RegisterArea override in the area registration class for each Area in your application. (For example, if you have an Area named Admin, this class will be called AdminAreaRegistration and will be located in theAreas/Admin folder.) Again, replace all the calls to MapRoute with MapRouteLowercase.

For example:

using LowercaseRoutesMVC
... public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRouteLowercase( // changed from context.MapRoute
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}

  

Step 4. (if using ASP.NET Web API) - Remap Your HTTP Routes

There is a separate Nuget package called LowercaseRoutesMVC4 that contains all of the functionality above, plus beta support for lower-casing HTTP Routes generated by the ASP.NET Web API. If this is something you're interested in doing, be sure to install the LowercaseRoutesMVC4 Nuget package and not the LowercaseRoutesMVC one. Keep in mind that the ASP.NET Web API is still in beta, and that the routing features are likely to change.

Go to the RegisterRoutes method in Global.asax. Replace all the calls to MapHttpRoute withMapHttpRouteLowercase.

For example:

using LowercaseRoutesMVC4
... public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapHttpRouteLowercase( // changed from routes.MapHttpRoute
"DefaultAPI",
"api/{controller}/{id}",
new { id = UrlParameter.Optional }
);
}

  

LowercaseRoutesMVC ASP.NET MVC routes to lowercase URLs的更多相关文章

  1. Professional C# 6 and .NET Core 1.0 - Chapter 41 ASP.NET MVC

    What's In This Chapter? Features of ASP.NET MVC 6 Routing Creating Controllers Creating Views Valida ...

  2. Asp.net MVC十问十答[译]

    1. Explain MVC (Model-View-Controller) in general? MVC (Model-View-Controller) is an architectural s ...

  3. 【Pro ASP.NET MVC 3 Framework】.学习笔记.12.ASP.NET MVC3的细节:URLs,Routing和Areas

    Adam Applied ASP.NET 4 in Context 1 介绍Routing系统 在引入MVC之前,ASP.NET假定被请求的URLs和服务器硬盘上的文件之间有着直接关系.服务器的任务是 ...

  4. ASP.NET MVC HttpVerbs.Delete/Put Routes not firing

    原文地址: https://weblog.west-wind.com/posts/2015/Apr/09/ASPNET-MVC-HttpVerbsDeletePut-Routes-not-firing ...

  5. 第2章 ASP.NET MVC(URL、路由及区域)

    * { font: 17px/1.5em "Microsoft YaHei" } ASPNET MVC URL.路由及区域 一.URL.路由及区域 一.      配置路由器 1. ...

  6. [译]Asp.net MVC 之 Contorllers(二)

    URL路由模块 取代URL重写 路由请求 URL路由模块的内部结构 应用程序路由 URL模式和路由 定义应用程序路由 处理路由 路由处理程序 处理物理文件请求 防止路由定义的URL 属性路由 书接上回 ...

  7. 七天学会ASP.NET MVC (六)——线程问题、异常处理、自定义URL

    本节又带了一些常用的,却很难理解的问题,本节从文件上传功能的实现引出了线程使用,介绍了线程饥饿的解决方法,异常处理方法,了解RouteTable自定义路径 . 系列文章 七天学会ASP.NET MVC ...

  8. [ASP.NET MVC 小牛之路]07 - URL Routing

    我们知道在ASP.NET Web Forms中,一个URL请求往往对应一个aspx页面,一个aspx页面就是一个物理文件,它包含对请求的处理. 而在ASP.NET MVC中,一个URL请求是由对应的一 ...

  9. 7、ASP.NET MVC入门到精通——第一个ASP.NET MVC程序

    本系列目录:ASP.NET MVC4入门到精通系列目录汇总 开发流程 新建Controller 创建Action 根据Action创建View 在Action获取数据并生产ActionResult传递 ...

随机推荐

  1. STL——map和set

    一.map 1.map被定义为一对(pair即key和value)数值. key值在map内最多只有一份. 假如需要对一篇文章中的单词计数,那么就可以建立一个map,string类型的key,int型 ...

  2. C++ vector二维数组

    C++ 构建二维动态数组 int **p; p = ]; //注意,int*[10]表示一个有10个元素的指针数组 ; i < ; ++i) { p[i] = ]; } 这样就构成10*5的数组 ...

  3. 39-Role以及Claims授权

    asp.net core多鼓励使用claims授权 1-使用role授权 在类或方法上贴上Roles,这样就知道有user的角色才可以访问 [Authorize(Roles="user&qu ...

  4. Sqoop帮助文档

    1.列出MySql数据库中的所有数据库 $ sqoop list-databases --connect jdbc:mysql://192.168.254.105:3306/--username ro ...

  5. jenkins安全内容配置策略

    有时我们使用HTML Publisher Plugin插件时,在jenkins点开html report,会发现没有带任何的css或js样式,这是因为Jenkins 1.641 / Jenkins 1 ...

  6. 用链表实现nodejs的内存对象管理

    虽然javascript拥有垃圾收集,但是垃圾收集机制并不会自动释放持久对象,比如websocks连接. 为了能够在某些特定情况下中止一些连接(比如内存不足),显然要建立全局的对象管理器进行管理. 显 ...

  7. HDU 4747 Mex(线段树)(2013 ACM/ICPC Asia Regional Hangzhou Online)

    Problem Description Mex is a function on a set of integers, which is universally used for impartial ...

  8. POJ 2166 Heapsort(递推)

    Description A well known algorithm called heapsort is a deterministic sorting algorithm taking O(n l ...

  9. python字符串排序方法

    一般情况下,python中对一个字符串排序相当麻烦: 一.python中的字符串类型是不允许直接改变元素的.必须先把要排序的字符串放在容器里,如list. 二.python中的list容器的sort( ...

  10. Linux TCP协议使用的变量

    Linux /proc/sys/net/ipv4/* 变量 TCP变量:somaxconn - INTEGER    listen()的backlog参数的上限,在用户态为SOMAXCONN.默认是1 ...