Question

i want to get the fully qualified url to a resource in ASP.NET.

e.g.:

<LINK rel="shortcut icon" href="<%=GetFaviconPath()%>">

with the code-behind file right now containing:

private String GetFaviconPath()
{
   String url = System.Web.VirtualPathUtility.ToAbsolute("~/Images/clock.ico");
   return url;
}

Unfortunately this doesn't work because it doesn't return the fully qualified path, only the path relative to the server:

/Employement/Images/clock.ico

Internet Explorer requires a fully qualified url, e.g.:

http://localhost:62119/Employment/Images/clock.ico

http://avenger:81/Employment/Images/clock.ico

http://MyFreeAspDotNetHosting.com/IanBoyd/Employment/Images/clock.ico

How can i get the fully qualified path to a file? i've tried VirtualPathUtility and i'm all out of ideas.

Was it helpful?

Solution

Try this

string _ApplicationPath = HttpContext.Current.Request.Url.ToString();

Append your relative path to that absolute path.

OTHER TIPS

You could append what you have to the result of

Request.Url.GetLeftPart(UriPartial.Authority)

Also, have a look at System.UriBuilder http://msdn.microsoft.com/en-us/library/wdwhd34a.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top