How to display URL in lower case?

谁说胖子不能爱 提交于 2019-12-24 05:21:51

问题


I have a webforms projects with uppercase URLs being returned to the client:

http://www.looknbook.com/Packages/Forms/package_search.aspx

The requirement is to have the URLs display in lowercase:

http://www.looknbook.com/packages/forms/package_search.aspx

How do I send URLs to the client's browser in lowercase in ASP.NET Webforms?


回答1:


For IIS7, you can use URI Rewrite and use the example here:

<rule name="Convert to lowercase" stopProcessing="true">  
    <match url=".*[A-Z].*" ignoreCase="false" />  
    <action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />
</rule>



回答2:


Classic ASP .NET paths correspond to folder names, and folders are not case-senstive in Windows.
Thefefore, both lowercase and capitalized URLs can be used to access your site.

The only reason you see an capitalized URL in the address bar is because the links have it capitalized. Change all links on the site to be lowercase, and that's it.

If you also want to force lowercase (i.e. change to lowercase even if the user entered a capitalized URL), you'll need to do URL rewriting but concrete solutions depend on the version of IIS you're using.




回答3:


if you want to achieve lower case URL from code site than we can achieve that by implementing following code in Application_BeginRequest or Application_EndRequest of global.cs page

            var curenturl = Request.Url.ToString();           
            if (Regex.IsMatch(curenturl, @"[A-Z]"))
            {
                Response.Clear();
                Response.Status = "301 Moved Permanently";
                Response.StatusCode = 301;
                Response.AddHeader("Location", curenturl.ToLower());
                Response.End();
            }


来源:https://stackoverflow.com/questions/7009944/how-to-display-url-in-lower-case

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