tags:

views:

70

answers:

3

hi folks., how to retrieve complete url of a website including http? example: http://stackoverflow.com/

+2  A: 

If you are looking for the complete URL from the current request context, the HttpRequest.Url property should do the trick. To get a string representation within a Page:

string completeUrl = Request.Url.ToString();
Jørn Schou-Rode
please specify me the namespace for Request.Url..thanks
SAK
The `HttpRequest` class is in the `System.Web` namespace. In my coe sample, `Request` is a property on `System.Web.Page`. A similar property is available `UserControl` and `HttpContext`.
Jørn Schou-Rode
sorry.. i am not using usercontrol ... i am using class file here..the thing is i am using dll..
SAK
I have no idea what you are trying to resolve, and I doubt that my answer is useful, but what about `System.Web.HttpContext.Current.Request.Url.ToString()` ?
Jørn Schou-Rode
what i am trying to resolve is switching a site between http and https..
SAK
+1  A: 

Its been a while but:

Request.ServerVariables["Url"];

http://msdn.microsoft.com/en-us/library/ms525396(VS.90).aspx

or even this reference from 1998!

http://www.4guysfromrolla.com/webtech/092298-3.shtml

EDIT

From http://www.w3schools.com/asp/coll_servervariables.asp

<html>
<body>
<p>
<b>You are browsing this site with:</b>
<%Response.Write(Request.ServerVariables("http_user_agent"))%>
</p>
<p>
<b>Your IP address is:</b>
<%Response.Write(Request.ServerVariables("remote_addr"))%>
</p>
<p>
<b>The DNS lookup of the IP address is:</b>
<%Response.Write(Request.ServerVariables("remote_host"))%>
</p>
<p>
<b>The method used to call the page:</b>
<%Response.Write(Request.ServerVariables("request_method"))%>
</p>
<p>
<b>The server's domain name:</b>
<%Response.Write(Request.ServerVariables("server_name"))%>
</p>
<p>
<b>The server's port:</b>
<%Response.Write(Request.ServerVariables("server_port"))%>
</p>
<p>
<b>The server's software:</b>
<%Response.Write(Request.ServerVariables("server_software"))%>
</p>
</body>
</html>
amelvin
+2  A: 

Maybe you mean to get the url of the current page?

Use: Request.Url.ToString()

Or if you want to convert a relative Url to the absolute path, I beleive the code is something like this:

Request.Url.Host + Page.ResolveUrl(relativeUrl)
Nathan Reed