简体   繁体   中英

How to display URL in lower case?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM