문제

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.

도움이 되었습니까?

해결책

Try this

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

Append your relative path to that absolute path.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top