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. SpringBoot学习(1)

    springboot的自动配置功能,主要流程如下: 1 启动的时候加载我们的主配置类,也就是我们的入口类:从而开启我们的自动配置配置功能,这个是通过@EnableAutoConfiguration注解 ...

  2. 【Leetcode】Jewels and Stones

    Jewels and Stones Description You're given strings J representing the types of stones that are jewel ...

  3. java入门---简介&简单输出小例子&开发前准备

        Java是由Sun Microsystems公司于1995年5月推出的Java面向对象程序设计语言和Java平台的总称.由James Gosling和同事们共同研发,并在1995年正式推出.J ...

  4. 20145202马超《网络对抗》Exp4 恶意代码分析

    20145202马超<网络对抗>Exp4 恶意代码分析 1.实验后回答问题 (1)总结一下监控一个系统通常需要监控什么.用什么来监控. 虽然这次试验的软件很好用,我承认,但是他拖慢了电脑的 ...

  5. PHP.40-TP框架商城应用实例-后台15-商品属性与库存量1-不同商品(唯一属性、可选属性),属性类型

    思路: 1.不同商品属于不同的类型,如:手机.服装.电脑等类型 2.不同的类型有不同的属性,其中分为唯一属性和可选属性,如服装:可选属性{尺寸:S,M,L……;颜色:白色,黑色……}唯一属性:材质 首 ...

  6. HashMap源码注释翻译

    HashMap.java(JDK1.8) 如有错误翻译的地方,欢迎评论指出. 介绍:对于HashMap及其子类而言,它们采用Hash算法来决定集合中元素的存储位置.当系统开始初始化HashMap时,系 ...

  7. Java与C++进行系统间交互:Protocol Buffer

    在一次项目中,因笔者负责的java端应用需要与公司C++系统进行交互,公司选定Protocol Buffer方案,故简单的了解一下 有需要的可以看一下其他作者的文章,了解一下Protobuf: htt ...

  8. Qt 实时读串口数据,并将读到的数据从网口发送出去

    需求: 1. 要试试从串口读取数据 2. 将读到的数据从网口发送出去 3.开机启动 4. 没有界面 第一部分 配置Qt Pro文件  需要Qt += serialport network 第二部分 - ...

  9. SQL SERVER 的操作复习

    一.数据库的创建(SQL语句)CREATE DATABASE AON PRIMARY --主文件组(    NAME='A_data',--逻辑文件名    --物理文件名    FILENAME=' ...

  10. Kubernetes实战 高可用集群搭建,配置,运维与应用

    1-1 K8S导学 1-2 搭建K8S集群步骤和要点介绍 1-3 搭建三节点Ubuntu环境 1-4 安装容器引擎 1-5 下载Kubeadm.node组件和命令行工具 1-6 向集群中加入worke ...