我们将来将使用 Windows Azure 网站来满足我们的基本托管需求。由于云与本地有非常具体的配置设置,您如何管理这些设置?以下面为例:
本地开发服务器:
string path = AppSettings["StoragePath"];
<add key="StoragePath" value="c:\temp" />
Windows Azure:
string path = AppSettings["StoragePath"];
<add key="StoragePath" value="xyz" />
您是否在每次发布之前手动更改配置文件中的 StoragePath 或者代码中是否有可以执行的操作,例如:
<add key="LocalStoragePath" value="c:\temp" />
<add key="BlobStoragePath" value="xyz" />
string path;
if (Azure)
{
path = AppSettings["BlobStoragePath"];
}
else
{
path = AppSettings["LocalStoragePath"];
}
如果后者可以,我如何确定环境是否是Windows Azure?
最佳答案
我通常会创建一个新的构建配置(称为 Azure)。
然后在 web.config 中创建您的 key ..
<add key="LocalStoragePath" value="c:\blah" />
<add key="AzureStoragePath" value="xyz" />
在你的代码中写入:
#if CONFIG == "Azure"
public const String storageKey = "AzureStoragePath";
#endif CONFIG == "Debug"
public const String storageKey = "LocalStoragePath";
#endif
并使用它:
String path = AppSettings[storageKey];
关于c# - 在 Visual Studio 中管理本地与云开发配置设置的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14555243/