MVC在_Layout.cshtml中打印连接字符串

MTZ*_*TZ4 1 asp.net-mvc connection-string razor

我需要在_Layout.cshtml中打印来自Web.config的连接字符串,任何想法如何?

Web.config文件:

  <connectionStrings>
    <add name="DConnectionString" connectionString="EnvName" />
  </connectionStrings>
Run Code Online (Sandbox Code Playgroud)

_Layout.cshtml:

<a class="navbar-brand" href="/"> [Print EnvName here] </a>
Run Code Online (Sandbox Code Playgroud)

谢谢!

Ofi*_*ris 5

使用:

<a class="navbar-brand" href="/">  
    @System.Configuration.ConfigurationManager.ConnectionStrings["DConnectionString"]
</a>
Run Code Online (Sandbox Code Playgroud)

这使用Razor语法来访问System.Configuration类.