How can I get the URL of the server my MVC3 project is being executed on? I do NOT want to hard code a server address.
I've got three servers I will be working with:
None of the above servers have the same URL.
My web project needs to generate notification emails that contain a clickable link.
I know that Request.Url.ToString() will get me the server but if possible, I'd rather not spend time processing that string everytime I generate an email.
You can process the Request.Url once and store the result in a static variable. Just make sure you access that variable in a thread-safe manner. I've been using this in production for quite a while, and it works like a charm.
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