I have an ASP.NET application and I would like to have a different logo depending on the environment (production, quality, etc...) so in my Site.Master page I have an image like this:

<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/logo_<%= EnvironmentHelper.GetRunningEnvironment() %>.png" AlternateText="logo"/>

The code behind is this:

    public static class EnvironmentHelper
{ public static string GetRunningEnvironment()
        return string.IsNullOrEmpty(ConfigurationManager.AppSettings["RunningEnvironment"]) 
            ? "dev"
            : ConfigurationManager.AppSettings["RunningEnvironment"];

I have added in the Site.Master page, the namespace so the method can be called:

<%@ Import Namespace="Business.Helpers" %>

In the Web.config file, I created a variable in appSettings section like this:

<add key="RunningEnvironment" value="dev"/>

I have several images in my images folder with all the environments (logo_prod.png, logo_dev.png, etc....)

The problem is that the logo doesn't get displayed and the url of the picture is:


why does the GetRunningEnvironment method is not evaluated ?

Related posts

Recent Viewed