Reputation: 3109
On on aspx.page On the code behind I want the full uri of another web page! Is there some standard function!
So say i am on
http:\\test.us\dir1\link1.aspx
In this page i want to get the full URI based on relative url
GetFullUri("~\dir2\link2.aspx")
Then returned is
http:\test.us\dir2\link2.aspx
Upvotes: 0
Views: 153
Reputation: 4550
You can write a function which takes the relative path is input and then based on the current URL it return the full path. Do not pass ~ as rel in the method
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;
}
Upvotes: 2