Application.Add(name,value)
.
我在另一个项目中有一个“应用程序外观”,我的服务层、数据层等都使用它来获取我需要进行的各种设置。
ConfigName | ConfigValue
WebServiceUsername | myUsername
WebServicePassword | myPassword
因此,在我的方法中,我从数据库中获取这些值,并将它们放入我的应用程序中:
protected void GetApplicationSettings()
{
//Get all the config values out of the database, and then put them into the application keys...
var appConfigAttributes = ApplicationConfigurationService.GetAppConfigNames();
foreach (var appConfig in appConfigAttributes)
{
Application.Add(appConfig.ConfigName,appConfig.ConfigValue);
}
}
这是我以后从应用程序调用值的方式:
public static string WebServiceUsername
{
get { return WebConfigurationManager.AppSettings["WebServiceUsername"]; }
}
如果我使用以下命令从web层调用应用程序facade:
<%= ApplicationFacade.WebServiceUsername %>
如果我手动将应用程序密钥放入web.config文件。。。
<appSettings>
<add key="putz" value="mash"/>
</appSettings>
然后在视图中进行调用时,在ApplicationFacade类中构建一个类似于Putz的属性(
<%= ApplicationFacade.Putz %>
)我明白了
mash
”他回答。
因此,我知道我的ApplicationFacade工作正常。所以可能是我在应用程序_start()中的代码?
好吧,如果我把这个放在我的角度来看
<%=Application["WebServiceUsername"]%>
myUsername
他回来了。
什么给了我?!
答复
ConfigurationManager.AppSettings.Set(appConfig.ConfigName,appConfig.ConfigValue);