gofor.net
gofor.net

Reputation: 4298

Similer like request.getContextPath() in Asp.Net

I need to know that,how we can get the current url path (e.g. http://www.mywebsite.com/) in asp.net. I found that java have the request.getContextPath() to get that. Even in dot net we have this, System.Web.HttpContext.Current.Request.UrlReferrer.Host System.Web.HttpContext.Current.Request.ApplicationPath

Is there any other ways that will gives the same result.

I am also interested to know how I will use the code in aspx page.

cheers.

Upvotes: 0

Views: 3022

Answers (3)

gofor.net
gofor.net

Reputation: 4298

I got this :)

http://<%=System.Web.HttpContext.Current.Request.UrlReferrer.Host+System.Web.HttpContext.Current.Request.ApplicationPath%>/page.aspx

cheers :) :)

Upvotes: 0

schei1
schei1

Reputation: 2487

Could context.Request.Url.ToString() do the trick your looking for?

context.Request.Url.ToString()

returns: "http://localhost:52550/myapp/somepage/"

Upvotes: 0

HatSoft
HatSoft

Reputation: 11201

I believe what you want is the HttpRequest.AppRelativeCurrentExecutionFilePath Property

The property gets the virtual path of the application root and makes it relative by using the tilde (~) notation for the application root (as in "~/page.aspx").

Upvotes: 1

Related Questions