on on aspx.page在后面的代码我想要另一个网页的完整uri!是否有一些标准功能!
所以说我在
http:\\test.us\dir1\link1.aspx
在此页面中,我想获得基于相对网址的完整URI
GetFullUri( “〜\ DIR2 \ link2.aspx”)
然后返回
HTTP:\ test.us \ DIR2 \ link2.aspx
答案 0 :(得分:2)
您可以编写一个函数,该函数接受相对路径输入,然后根据当前URL返回完整路径。不要在方法中将〜作为rel传递
URL used for this example:
http://localhost:12345/site/page.aspx?q1=1&q2=2
Value of HttpContext.Current.Request.Url.Host
localhost
Value of HttpContext.Current.Request.Url.Authority
localhost:12345
Value of HttpContext.Current.Request.Url.AbsolutePath
/site/page.aspx
Value of HttpContext.Current.Request.ApplicationPath
/site
Value of HttpContext.Current.Request.Url.AbsoluteUri
http://localhost:12345/site/page.aspx?q1=1&q2=2
static string (HttpContext context , string rel)
{
return HttpContext.Current.Request.Url.Scheme + "://" HttpContext.Current.Request.Url.Authority + rel;
}