Reputation: 131
I need to redirect to the CommonPage.aspx
page of my application when the session expires.
My application url would be similar to http://Name_IP/applicationname/FolderName/Home.aspx
From the above url I need to redirect to http://Name_IP/applicationname/commonpage.aspx
I have used below code to redirect
"http://localhost://" + Request.Url.Port.ToString() + "//applicationname/commonpage.aspx"
The above code will work in localhost. But it is not working after deployment. How to do that? Please suggest
How to replace the localhost with Name_IP?
Upvotes: 0
Views: 2391
Reputation: 28097
A good way to do this is by creating a new Uri
:
var uri = new Uri(Request.Url, "applicationname/commonpage.aspx");
this will return a Uri
who's value is
http://foo.bar:8080/applicationname/commonpage.aspx
Upvotes: 1
Reputation: 28097
You can get the hostname, including port by using
Request.Url.GetLeftPart(UriPartial.Authority)
which you can then use like
var url = String.Format(
"{0}/{1}"
Request.Url.GetLeftPart(UriPartial.Authority),
"applicationname/commonpage.aspx")
which will produce something like
http://foo.bar:8080/applicationname/commonpage.aspx
Upvotes: 0
Reputation: 108975
Request.Url
contains the complete URL from the request. Look at the Host
property.
Upvotes: 1