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. 使用mysql5.7版本数据库需要注意的地方/持续更新

    数据库mysql 5.7版本的初始密码修改 安装完后实在是找不到初始密码的文件,后面发现再错误日志中 先关闭mysql pkill mysqld 安全模式启动数据库并修改密码 mysqld_safe ...

  2. 对URI的理解

    在了解RESTful api的设计规范的时候,遇到了一个问题,就是uri和url有什关系,有什么区别,所以就在这里记录一下. URI(Uniform Resource Identifier),统一资源 ...

  3. (数据科学学习手札17)线性判别分析的原理简介&Python与R实现

    之前数篇博客我们比较了几种具有代表性的聚类算法,但现实工作中,最多的问题是分类与定性预测,即通过基于已标注类型的数据的各显著特征值,通过大量样本训练出的模型,来对新出现的样本进行分类,这也是机器学习中 ...

  4. 牛客暑假多校第五场A.gpa

    一.题意 给出你的N门课程的考试成绩和所占的机电数目.允许你放弃K门课的成绩,要求你的平均学分绩最高能达到多少. Kanade selected n courses in the university ...

  5. 安装sql server

    因为电脑中只有mysql数据库,所以昨天准备安装一个sql server.安装中出现了许多问题,首先第一遍的时候,安装组件中没有勾选管理工具这个选项,所以在最后的时候,文件夹中只有配置管理器,没有数据 ...

  6. 基于Ubuntu Server 16.04 LTS版本安装和部署Django之(三):设置上传文件夹权限(这里测试用完全共享)

    基于Ubuntu Server 16.04 LTS版本安装和部署Django之(一):安装Python3-pip和Django 基于Ubuntu Server 16.04 LTS版本安装和部署Djan ...

  7. js字符串操作函数

    js字符串函数 JS自带函数 concat 将两个或多个字符的文本组合起来,返回一个新的字符串. var a = "hello"; var b = ",world&quo ...

  8. ArrayMap java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Object[]

    错误堆栈: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Object[] at android ...

  9. nodejs环境搭建与express安装配置

    一.NPM 1.下载nodeJS 下载地址:https://nodejs.org/en/download/ 因为我的系统是Linux 的,所以下载已经编译好的Linux,nodejs tar包 3.下 ...

  10. https 通信流程和Charles 抓包原理

    1. https 通信流程 ①客户端的浏览器向服务器传送客户端SSL 协议的版本号,加密算法的种类,产生的随机数,以及其他服务器和客户端之间通讯所需要的各种信息.②服务器向客户端传送SSL 协议的版本 ...