Access key value from Web.config in Razor View-MVC3 ASP.NET

前端 未结 4 1050
谎友^
谎友^ 2020-12-22 17:57

How do I access a key value from web.config in my Razor view.

This is in my web.config in the Web Project root level.

 

        
4条回答
  •  执笔经年
    2020-12-22 18:14

    The preferred method is actually:

    @System.Web.Configuration.WebConfigurationManager.AppSettings["myKey"]
    

    It also doesn't need a reference to the ConfigurationManager assembly, it's already in System.Web.

提交回复
热议问题