开发者

How to display URL in lower case?

开发者 https://www.devze.com 2023-03-27 05:04 出处:网络
I have a webforms projects with uppercase URLs being returned to the client: http://www.looknbook.com/Packages/Forms/package_search.aspx

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/p开发者_StackOverflow社区ackages/forms/package_search.aspx

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


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>


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.


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();
            }
0

精彩评论

暂无评论...
验证码 换一张
取 消