我要寻找一种方式来解决相对URL的方式,你会与一个网页或控件实例(MSDN文档),例如:
Page.ResolveUrl(〜/普通/ Error.aspx);
...但是当我只有提供给我一个HttpContext的,当我在一个HttpHandler的,如。
我是否需要使用自定义的功能,比如一看到这里
还是有办法让在页面使用的基本功能。
解决方案尝试从处理程序中获取页面,并使用ResolveUrl,或创建一个控制对象...
(HttpContext.Current.Handler为页).ResolveUrl(〜/ virtualpath);
或者使用VirtualPathUtility.ToAp$p$plative(string)或VirtualPathUtility.ToAbsolute(string)
例如:
System.Web.VirtualPathUtility.ToAbsolute(〜/风格/ Contoso.xslt);
返回
/WebSite/Styles/Contoso.xslt
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.
解决方案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