How can I retrieve the complete url of the current webpage, including http? For example: https://stackoverflow.com/
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)
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();
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!
https://web.archive.org/web/20210927201638/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>
精彩评论