【发布时间】:2012-08-02 12:50:45
【问题描述】:
我想我一定是错过了慢猎豹的一些东西。我创建了一个新的 asp.net mvc3 应用程序。向 web.config 添加了一个具有默认值的 appsetting。然后我为每个调试和发布配置文件添加了一个转换。我还创建了一个读取该值的视图。当我预览转换时,转换工作正常。我的理解是,如果我在发布模式下运行项目,那么项目将从发布转换中读取应用程序设置,如果我在调试模式下运行项目,它将从调试配置中读取应用程序设置。
这里是 web.config 的相关部分
<appSettings>
<add key="cheetah_val" value="default_val"/>
</appSettings>
这里是 web.debug.config
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="cheetah_val" value="debug_val" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
</appSettings>
<system.web>
</system.web>
</configuration>
这里是 web.release.config
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="cheetah_val" value="release_val" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
</appSettings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
HomeController.cs
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.CheetahMessage = System.Configuration.ConfigurationManager.AppSettings["cheetah_val"];
return View();
}
}
还有index.cshtml
@{
ViewBag.Title = "Home Page";
}
<h2>@ViewBag.CheetahMessage</h2>
我希望在发布模式下输出为 release_val,在调试模式下为 debug_val。我究竟做错了什么?还是我错过了一些重要的东西?对于网站,F5 功能不起作用吗?对于网站,我是否必须实际发布此内容才能使转换生效?
【问题讨论】: