Short version:
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.
Long version:
I’ve got three servers I will be working with:
- Development server
- QA server for others to test
- Production server
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.Urlonce 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.