Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't request.rawurl include the http://localhost part?

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...)

like image 485
user255963 Avatar asked Jan 26 '10 15:01

user255963


People also ask

What is raw url in HTTP request?

System. Web Http Request. Raw Url Property System. Web Gets the raw URL of the current request. The raw URL of the current request. The following code example uses the HtmlEncode method to HTML-encode the value of the RawUrl property and the WriteLine method to write the encoded value to the file.

Can a website make an HTTP request to localhost?

To answer the question: Yes a website can make an HTTP request to localhost. It will not break cross domain policy, because the request will not cross domains. It will stay local. One way to avoid cross domain policies, is to get the target victim to make the HTTP request themselves.

What does the URL property of an httprequest return?

However, the URL property of an HTTPRequest object returns a System.URI object, which also contains server name. Show activity on this post. Request.RawUrl is very similar to Request.Url.PathAndQuery except that Request.Url.PathAndQuery includes the Default Document if one was used whereas Request.RawUrl does not.

What is the difference between raw url and pathandquery in ASP NET?

Request.RawUrl is very similar to Request.Url.PathAndQuery except that Request.Url.PathAndQuery includes the Default Document if one was used whereas Request.RawUrl does not. From my experience, this is true for ASP.Net 4.0 and higher.


2 Answers

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.AbsoluteUri to get the entire thing.

like image 173
Klaus Byskov Pedersen Avatar answered Nov 15 '22 11:11

Klaus Byskov Pedersen


See what you get with Request.Url.

like image 31
DOK Avatar answered Nov 15 '22 12:11

DOK