Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am looking for a way to resolve a relative url the way you would with a page or control instance (MSDN Docs) such as:

Page.ResolveUrl("~/common/Error.aspx");

...but when I only have an HttpContext available to me, such as when I am in a HttpHandler.

Will I need to use a custom function, such as the one seen here?

Or is there a way to get at the underlying function used by the Page.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
412 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try to get the page from the handler and use ResolveUrl, or create a Control object...

(HttpContext.Current.Handler as Page).ResolveUrl("~/virtualpath");

Or use VirtualPathUtility.ToAppRelative(string) or VirtualPathUtility.ToAbsolute(string)

For example:

System.Web.VirtualPathUtility.ToAbsolute("~/Styles/Contoso.xslt");

returns

/WebSite/Styles/Contoso.xslt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...