I want to get the website url without subfolders, I mean everything replaced by ~
For example:
http://www.myWebAp开发者_运维百科plication.com/a
http://www.myWebApplication.com?somepage=b
I just want: http://www.myWebApplication.com
http://www.myWebApplication:3345/c
I just want: http://www.myWebApplication:3345
Any help!
var url = new Uri("http://www.myWebApplication:3345/c");
var siteAddress = url.Scheme + Uri.SchemeDelimiter + url.Host +
(url.IsDefaultPort? "":(":" + url.Port));
If it's the Request url, you can get it from Request.Url
instead of building a new Uri.
var uriBuilder = new System.UriBuilder
{
Host = HttpContext.Request.Url.Host,
Path = "/",
Port = HttpContext.Request.Url.Port,
Scheme = HttpContext.Request.Url.Scheme
};
var websiteUrl = uriBuilder.ToString();
Just use HttpContext.Current.Request.Url.Host
Edit: You can play around HttpContext.Current.Request.Url to get most of the information you need from the URL
精彩评论