I want to get the all the path of URL except the current page of url, eg: my URL is http://www.MyIpAddress.com/red/green/default.aspx I want to get "http://www.MyIpAddress.com/red/green/" only. How can I get.I'm doing like
string sPath = new Uri(HttpContext.Current.Request.Url.AbsoluteUri).OriginalString; System.Web.HttpContext.Current.Request.Url.AbsolutePath; sPath = sPath.Replace("http://", ""); System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath); string sRet = oInfo.Name; Response.Write(sPath.Replace(sRet, ""));
Its showing exception on new System.IO.FileInfo(sPath) as sPath contain "localhost/red/green/default.aspx" saying "The given path's format is not supported."
So yes, file URIs are URLs.
Url. AbsoluteUri is returning "http://www.somesite.com/default.aspx" , when the Url in the client's browser looks like "http://www.somesite.com/". This small diffrence is causing a redirect loop.
Inject NavigationManager in razor. Use Uri from NavigationManager to get the current URL.
Main URL : http://localhost:8080/mysite/page.aspx?p1=1&p2=2
Get different parts of URL in C#.
Value of HttpContext.Current.Request.Url.Host localhost Value of HttpContext.Current.Request.Url.Authority localhost:8080 Value of HttpContext.Current.Request.Url.AbsolutePath /mysite/page.aspx Value of HttpContext.Current.Request.ApplicationPath /mysite Value of HttpContext.Current.Request.Url.AbsoluteUri http://localhost:8080/mysite/page.aspx?p1=1&p2=2 Value of HttpContext.Current.Request.RawUrl /mysite/page.aspx?p1=1&p2=2 Value of HttpContext.Current.Request.Url.PathAndQuery /mysite/page.aspx?p1=1&p2=2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With