问题
In ASP.Net
it is posible to get same content from almost equal pages by URLs like
localhost:9000/Index.aspx
and localhost:9000//Index.aspx
or even localhost:9000///Index.aspx
But it isn't looks good for me.
How can i remove this additional slashes before user go to some page and in what place?
回答1:
Use this :
url = Regex.Replace(url , @"/+", @"/");
it will support n times
回答2:
see
https://stackoverflow.com/a/19689870
https://msdn.microsoft.com/en-us/library/9hst1w91.aspx#Examples
You need to specify a base Uri and a relative path to get the canonized behavior.
Uri baseUri = new Uri("http://www.contoso.com");
Uri myUri = new Uri(baseUri, "catalog/shownew.htm");
Console.WriteLine(myUri.ToString());
回答3:
This solution is not that pretty but very easy
do
{
url = url.Replace("//", "/");
}
while(url.Contains("//"));
This will work for many slashes in your url but the runtime is not that great.
回答4:
Remove them, for example:
url = url.Replace("///", "/").Replace("//", "/");
回答5:
Regex.Replace("http://localhost:3000///////asdasd/as///asdasda///asdasdasd//", @"/+", @"/").Replace(":/", "://")
来源:https://stackoverflow.com/questions/30483947/remove-additional-slashes-from-url