Right now I have an MVC application running on http://127.0.0.1:8081/ (it is actually running in the Azure compute emulator). The browser location bar clearly says 8081 for the port number.
However, Request.Url and Request.RawUrl both give me http://127.0.0.1:8082/.
I need to send an e-mail with a URL in it, so I need the correct hostname and port number. How do I get the actual, real URL reliably and without such unexpected deviation?
You can use Request.Headers["Host"]; which will give you the host name (or IP) with the correct port number. Then you can reconstruct the URL.
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