I've read conflicting things on this: In ASP.Net (and MVC), does the Request.Url.Host return the host header for the request? I've seen code that checks for Request.Headers["host"] first, then degrades to using Request.Url.Host if there is a problem, but I don't understand why this would be needed if they are identical.
They're not identical.
HttpRequest.Headers["Host"] gives you direct access to the client-to-server HTTP header.
HttpRequest.Url is rebuilt by ASP.NET and it does use the incoming request's Host: header by default, however there is an internal setting UseHostHeaderForRequestUrl, if this is set to false then ASP.NET will use HttpRequest.Headers["SERVER_NAME"] instead, but under certain circumstances it uses value of "127.0.0.1" instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With