URL of requested page

G

Gary Larimer

In the Page_Load() event, what Class, method do I use to retrieve the URL of
the current aspx page?

Thanks for any comments\information.
 
J

Juan T. Llibre

G

Göran Andersson

Juan said:
re:
!> Response.Write(Request.RawUrl);

That's incorrect.

Request.RawUrl returns a relative url, not an absolute url.
Request.RawUrl example : /virtualdirectory/requestrawurl.aspx

Request.Url.ToString returns the fully qualified url.
Request.Url.ToString example : http://www.server.com/virtualdirectory/requesturl.aspx

Well, to be fair the OP actually didn't specify that he wanted an
absolute url.

There is another difference that should be adressed, though. The RawUrl
property contains the URL that the request from the user contains, while
the Url property contains the URL of the page actually handling the
request. Those might not be the same if you for example use the
HttpContext.RewritePath or HttpServer.Transfer methods.

Which one is better, depends on what information the OP really is after.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top