8

I want to send an email to the user where he can click on link to transfer to my site. I don't want to hard code the url in my Email Templates. I want this dynamic in a sense that whatever the environment it will send the related url. Like If I am on the development environment it send something like http://localhost:port or in production send the actual website url. http://www.domain.com

I just need to know how can I save it in DynamicViewBag in MVC Action. Any suggestion plz?

Ammar Khan
  • 2,565
  • 6
  • 35
  • 60

2 Answers2

17

You can use the properties of the Request object, for example

var request = HttpContext.Current.Request
var address = string.Format("{0}://{1}", request.Url.Scheme, request.Url.Authority);
11

You can do this:

var dynamicViewBag = new DynamicViewBag();
dynamicViewBag.AddValue("BaseUrl", Request.Url.GetLeftPart(UriPartial.Authority));
David
  • 325
  • 3
  • 12
  • How can I set this in DynamicViewBag? – Ammar Khan Jul 05 '14 at 10:41
  • Thank you very much. Could you pleas also let me know, how do I access it in view? By the way I marked your suggestion as answer because this is what I really asked in the question. Wondering if you please help me to access it in view – Ammar Khan Jul 05 '14 at 10:57