我正在使用MVC3,我想知道区分您的环境的最佳方式是什么?例如,我正在考虑为appSettings添加一个键并引用它,但是在MVC3中有更好的方法吗?我正在研究3个环境:开发,分期和生产。区分MVC3环境的最佳方法?
感谢
我正在使用MVC3,我想知道区分您的环境的最佳方式是什么?例如,我正在考虑为appSettings添加一个键并引用它,但是在MVC3中有更好的方法吗?我正在研究3个环境:开发,分期和生产。区分MVC3环境的最佳方法?
感谢
我使用配置管理器并定义调试,测试,发布的编译时间常数。对于配置我使用Web.config Transformation Syntax for Web Application Project Deployment,并强烈建议使用它们。
例如:
//web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="MyConnectionString"
connectionString="Data Source=SqlServer\Sql2008;
Initial Catalog=MyDB.Dev;
Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
</connectionStrings>
<add key="SomeAppSetting"
value="DebugValue"/>
</configuration>
测试转型:
//web.Test.config
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MyConnectionString"
connectionString="Data Source=SqlServer\Sql2008;
Initial Catalog=MyDB.Test;
Integrated Security=SSPI"
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes"
xdt:Locator="Match(name)"/>
</connectionStrings>
<add key="SomeAppSetting"
value="TestValue"
xdt:Transform="SetAttributes"
xdt:Locator="Match(key)"/>
</configuration>
当我改变从调试我的配置,测试和重建/部署我的应用程序现在使用的改造更新我的web.Test.config
。非常有用。
您可以使用Configuration Manager Dialog Box构建不同的配置。在任何时候,您都可以右键单击web.config并选择添加配置转换以使Visual Studio 2010以自动方式创建转换配置文件。
对于MVC UI项目,Web.config可能是一个很好的地方。假设数据层和服务层是分开的,那么您也可以在其他项目中使用条目。
我建议看看web config transformation。一旦你有了你的web.config设置的基础,你将为你的分段和生产环境创建一个转换。
如果你需要更多的信息,很多很好的例子。
+1在发布之后才刷新我的屏幕 – Jesse