I need to be able to get at the full URL of the page I am on from a user control. Is it just a matter of concatenating a bunch of Request variables together? If so which ones? Or is there a more simpiler way?
+1
A:
if you need the full URL as everything from the http to the querystring you will need to concatenate the following variables
Request.ServerVariables("HTTPS") // to check if it's HTTP or HTTPS
Request.ServerVariables("SERVER_NAME")
Request.ServerVariables("SCRIPT_NAME")
Request.ServerVariables("QUERY_STRING")
Christian Hagelid
2008-09-02 21:16:36
A:
Thanks guys, I used a combination of both your answers @Christian and @Jonathan for my specific need.
"http://" + Request.ServerVariables["SERVER_NAME"] + Request.RawUrl.ToString()
I don't need to worry about secure http, needed the servername variable and the RawUrl handles the path from the domain name and includes the querystring if present.
RedWolves
2008-09-02 21:27:38
You should also know that RawUrl, unlike Request.Url, represents the original, unmapped request url if url mapping is being used.
harpo
2008-09-09 05:44:23
+3
A:
I usually use Request.Url.ToString()
to get the full url (including querystring), no concatenation required.
travis
2008-09-03 03:49:18
A:
Request.Url.AbsoluteUri
This property does everything you need, all in one susinct call.
DevelopingChris
2008-09-03 05:06:25