Asp.net 获取网页的完整url
在aspx.page上的代码后面,我想要另一个网页的完整uri!是否有一些标准功能 所以说我在Asp.net 获取网页的完整url,asp.net,Asp.net,在aspx.page上的代码后面,我想要另一个网页的完整uri!是否有一些标准功能 所以说我在 http:\\test.us\dir1\link1.aspx 在这个页面中,我想获得基于相对url的完整URI GetFullUri(“~\dir2\link2.aspx”) 然后返回的是 http:\test.us\dir2\link2.aspx 您可以编写一个函数,该函数接受输入的相对路径,然后根据当前URL返回完整路径。请勿在方法中以rel形式传递~ URL used for t
http:\\test.us\dir1\link1.aspx
在这个页面中,我想获得基于相对url的完整URI
GetFullUri(“~\dir2\link2.aspx”)
然后返回的是
http:\test.us\dir2\link2.aspx
您可以编写一个函数,该函数接受输入的相对路径,然后根据当前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;
}
谢谢你的回复!为什么我不应该传递~~不是您需要的URL的一部分。