ASP.NET MVC 3 Case Sensitive URLs

北城以北 提交于 2019-12-12 09:56:27

问题


I am doing a bad thing here. I am asking a question without trying out first by hopping that someone knows an easy way of doing this.

Any chance we can make ASP.NET MVC Routing system case sensitive? I would like the following two Urls to be different:

example.com/a

example.com/A

Do we have an easy fix or should write our own handler for this.


回答1:


I haven't tried it, but I would think that if you use a regular expression route constraint that only matched the uppercase and lowercase seperate, that would work. I don't think it's a good idea though.




回答2:


That seems like a bad idea. You're assuming that folks will never touch a url by hand, always clicking links.

Plus, by default, MSSQL is case insensitive, assuming that some of your route values are database bound.

I'd also be willing to bet that all urls in the search engines are lower case( Edumacated guess ).

EDIT

All google paid search urls are lower case.

If you STILL insist on doing this:

You also may have to have implement a custom viewengine that looks for the views on a case sensitive basis. Also a custom controller factory to find controllers that are case sensitive.




回答3:


Also note that regex options like case sensitivity can be changed mid regex by things like:

...(?-i:nonCaseSensitiveBit)backToCaseInsensitive...

See the Regex docs for the full readout.



来源:https://stackoverflow.com/questions/9518064/asp-net-mvc-3-case-sensitive-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!