Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is the best way to get the current URL with no query strings? Please note, I need the ENTIRE URL. From Http - .com or whatever!!

Thanks in advance
Posted

Try this code :thumbsup:
currentUrl = Request.Url;
 
Share this answer
 
Comments
#realJSOP 25-Jun-11 10:29am    
5 - proposed as answer
DominicZA 25-Jun-11 10:54am    
That returns the URL with the query string! I tried that!
ambarishtv 25-Jun-11 11:04am    
this link will help you
http://www.sitepoint.com/forums/classic-asp-148/how-remove-query-string-url-436836.html
#realJSOP 25-Jun-11 14:44pm    
Then remove everything starting with the first '?' character in the string, and voila - just a URL.
hello,

Maybe this is what you looking for (from http to .com/.net, etc...)

<br />
String myUrl = Request.Url.Scheme + Uri.SchemeDelimiter +Request.Url.Host;<br />


More example:
http://stackoverflow.com/questions/21640/net-get-protocol-host-and-port[^]
 
Share this answer
 
v2
hi
use this code below
C#
string orginalUrl = HttpContext.Current.Request.Url.AbsoluteUri;
               if (HttpContext.Current.Request.Url.Query.Length > 0)
                   orginalUrl = orginalUrl.Replace(HttpContext.Current.Request.Url.Query, string.Empty);
 
Share this answer
 
Comments
DominicZA 25-Jun-11 11:33am    
I can't check this right now but this looks pretty delicious!Can't believe I didn't think of it :P thanks!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900