tags:

views:

259

answers:

2

Hi there,

been playing around with ResolveClientUrl("~/Confirmation.aspx") and other methods..

I am tryin go get the FULL absolute URL of the page including Http: etc etc..

Anyone knows how to do this?

thanks

+2  A: 
Request.Url.ToString()

gets the absolute URL for the current request.

If you want to get it for a relative path:

Request.Url.GetLeftPart(UriPartial.Authority) 
                      + VirtualPathUtility.ToAbsolute(relativePath)
Mehrdad Afshari
but this gets the full url of the page.. need to get the base and using ~Nameofpage.aspx to append it
mark smith
-1: This only works if the page you want a handle to is the page you're operating in the context of right now.
DDaviesBrackett
@mark: There's no direct method to do that. That's your best bet.
Mehrdad Afshari
@DDaviesBrackett: I updated the answer to handle that case too.
Mehrdad Afshari
thanks .. works like a charm
mark smith
A: 

This will get you the url up to the root of the asp.net application (including virtual folders in IIS). From there you can just append the relative path of the file you want to reference

string url = HttpContext.Current.Request.Url.AbsoluteUri.Replace(
    HttpContext.Current.Request.Url.AbsolutePath, string.Empty) +
    HttpContext.Current.Request.ApplicationPath;

if (!url.EndsWith("/")) url += "/";

url += "path/to/myfile.jpeg";
Clyde
Path.Combine for a virtual path? Good luck with that.
Mehrdad Afshari
Sorry, spazzed out with Path.Combine. Fixed
Clyde
In any case, the meat of the answer is using Url.AbsolutePath and Request.ApplicationPath. That will work fine
Clyde
Btw, this doesn't handle ~ correctly.
Mehrdad Afshari