【发布时间】:2016-10-20 09:12:50
【问题描述】:
我有一个 Web 应用程序并开发了一些 API。每当 API 成功时,我都会传递一条消息。我想在发布此应用程序更改消息后进行更改。所以我想知道如何像这样开发。
【问题讨论】:
标签: c# model-view-controller asp.net-web-api
我有一个 Web 应用程序并开发了一些 API。每当 API 成功时,我都会传递一条消息。我想在发布此应用程序更改消息后进行更改。所以我想知道如何像这样开发。
【问题讨论】:
标签: c# model-view-controller asp.net-web-api
最简单的方法是在 web.config 文件中添加一个标志,例如添加这个键:
<appSettings><add key="IsDebug" value="True" /></appSettings>
并将此密钥添加到 Web.Release.config 文件中:
<appSettings><add xdt:Transform="SetAttributes" xdt:Locator="Match(key)" key="IsDebug" value="False" /></appSettings>
然后你可以在你的代码中勾选“IsDebug”键,例如:
NameValueCollection appSettings = ConfigurationManager.AppSettings;
string isDebug = appSettings["IsDebug"]);
if(isDebug == "True")
{
// your debug version message
}
then
{
// your release version message
}
【讨论】: