从布局页面访问MVC应用程序设置

问题描述 投票:0回答:1

我正在尝试进一步帮助组织的用户知道他们所处的环境就是我们的测试环境。我已经在web.config的“应用程序设置”部分中放置了一个设置,然后在web.release.config中对该设置进行了变换(替换)。我要做的就是将我们的徽标从正常颜色切换为红色。下面是我尝试过的方法,它总是转到else语句选项。

@if (System.Configuration.ConfigurationManager.AppSettings["Environment"] == "PROD")
            {
                <img src="~/Content/Img/default/sru_logo.png" class="sruLogo" alt="" />
            }
            else if (System.Configuration.ConfigurationManager.AppSettings["Environment"] == "PPRD")
            {
                <img src="~/Content/Img/default/sru_logo_test.png" class="sruLogo" alt="" />
            }
            else
            {
                <p>Not Working</p>
            }

我尝试使用Context.Application [“ Environment”],System.Web.Configuration.WebConfigurationManager.AppSettings [“ Environment”]

以上都不起作用,正如我所说,我要尝试做的就是根据应用程序设置在_Layout.cshtml文件中使用其他图像。

asp.net-mvc layout asp.net-mvc-5 web-config
1个回答
0
投票

尝试使用圆括号代替suqare

System.Configuration.ConfigurationManager.AppSettings("Environment");

© www.soinside.com 2019 - 2024. All rights reserved.