开发者

Get URL of current page in ASP.net [closed]

开发者 https://www.devze.com 2023-01-01 02:05 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot b开发者_运维技巧e reasonably answered in its current form.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot b开发者_运维技巧e reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消