I am building a site that will eventually pull images from a separate domain. That domain doesn't exist yet, nor has its name even been concluded upon, so for the time being I need to access images from a local directory. To avoid manually changing every single image tag later on, I want to use a global variable that I can change once and affect every single image tag on the website.
I have found one solution thus far, which is to set a key/value pair in Web.config's appSettings like so...
<appSettings> <add key="ImageSource" value="/some/local/directory" /> </appSettings> Then, in each view, at the top, I add...
@{ string imgsrc = System.Configuration.ConfigurationManager.AppSettings["ImageSource"]; } And in the HTML I use...
<img src="@imgsrc/my_image.jpg" alt="my image" /> This works but it still requires me to assign the variable in every single view template that I create. In the spirit of DRY, I am looking for some way that I can assign the variable once and have its presence implicit in every page, regardless of model, controller, or view.