ASP.NET MVC3:调试和发布应用程序设置不工作
我的调试和发布不被正确读取web.config中的应用程序设置。
My debug and release web.config app settings are not being read correctly.
Web.config文件:
Web.config:
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
Web.Debug.config
Web.Debug.config
<appSettings>
<add key="ErrorEmailAddress" value="developerEmail@email.com" />
<add key="TestModeEmailAddress" value="developerEmail@email.com" />
</appSettings>
Web.Release.config
Web.Release.config
<appSettings>
<add key="ErrorEmailAddress" value="prodErrorEmail@email.com" />
</appSettings>
不过,美其名曰:
However, calling:
WebConfigurationManager.AppSettings["ErrorEmailAddress"]
时,返回null(调试时)。
is returning null (when debugging).
我曾尝试加入XDT:转换=插入例如
I have tried adding xdt:Transform="Insert" e.g.
<add key="ErrorEmailAddress" value="prodErroEmail@email.com" xdt:Transform="Insert" />
任何想法?
好吧,我想通了。
在这里找到答案:How我可以使用Web.debug.config在内置Visual Studio调试服务器?
所以,当你发布配置文件只相结合,而不是当您运行针对本地服务器。 pretty愚蠢IMO,当别人将你曾经使用Web.Debug.config?
So the config files are only combined when you publish, not when you are running against a local server. Pretty stupid IMO, when else would you ever use Web.Debug.config?
我将做的是在这里建议:Use Visual Studio中的web.config变换调试
I will do as is suggested here: Use Visual Studio web.config transform for debugging
,只是有作为的Web.config我的默认调试配置文件,然后有释放的时候发布。不能看到Web.Debug.config一个用作了这一点。
and just have Web.config as my default debugging config file, then have release for when releasing. Can't see a use for Web.Debug.config as this point.
不过,因为大多数我的设置我想对所有的环境中设置的一种方式,但开发时(如在的customErrors),这是烦人。这意味着我必须设置它们在Web.config中进行调试,然后在我的所有其他环境CONFIGS更改。
Still, this is annoying because most of my settings I want to be set one way for all environments but when developing (eg customErrors On). This means I have to set them in Web.config for debugging, then in all my other environment configs change them.
谢谢大家的响应。