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
2010-05-21 09:37:31
please specify me the namespace for Request.Url..thanks
SAK
2010-05-21 10:04:26
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
2010-05-21 10:10:16
sorry.. i am not using usercontrol ... i am using class file here..the thing is i am using dll..
SAK
2010-05-21 10:17:35
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
2010-05-21 10:23:23
what i am trying to resolve is switching a site between http and https..
SAK
2010-05-21 10:35:14
+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
2010-05-21 09:41:28
+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
2010-05-21 09:41:39