views:

285

answers:

5

When I call Request.RawUrl I am not getting the domain name (at least in development).

For example, if my url locally is:

http://localhost:2343/some/thing

The call to Request.RawUrl is giving me back:

/some/thing

I recall it returns everything, is this the behaviour b/c it is local dev?

Update

I am also using Url Re-Writing so things like Request.Url.AbsoluteUri return back the internal url, not the re-written url that i need to get.

is javascript the only way then?

Or I maybe I can use Request.RawUrl for the url part, and then just get the domain name part somehow? (sometimes it has a port too...)

+1  A: 

See what you get with Request.Url.

DOK
A: 

The RawUrl returns just that, the URL after your domain.

See this page for an example of RawURL.

Shawn Steward
+3  A: 

According to the documentation:

The raw URL is defined as the part of the URL following the domain information. In the URL string http://www.contoso.com/articles/recent.aspx, the raw URL is /articles/recent.aspx. The raw URL includes the query string, if present.

You can use Request.Url.AbsoluteUrl to get the entire thing.

klausbyskov
Problem is I am using url re-writting, so maybe the only way is to get the url via javascript?
A: 

From the MSDN document on Request.RawUrl:

The raw URL is defined as the part of the URL following the domain information.

You are looking for Request.Url.

Oded
A: 

That behaviour is by design. RawUrl only returns the part of the url following the domain name, plus any querystring parameters.

If you want the full url, use Request.Url.

Brandon