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/Emp开发者_如何学JAVAloyment/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.
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
Try this
string _ApplicationPath = HttpContext.Current.Request.Url.ToString();
Append your relative path to that absolute path.
精彩评论