作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想获取一个 logFilePath 值,该值是我通过硬编码提供给 appSettings 的。我试图通过以下方式达到关键值
System.Configuration.Configuration rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);
System.Configuration.KeyValueConfigurationElement customSetting = rootWebConfig1.AppSettings.Settings["azureLogUrl"];
string pathValue = customSetting.Value;
但我收到了空引用异常。如何从 web.config 文件中获取值?
最佳答案
用途:
string pathValue = ConfigurationManager.AppSettings["azureLogUrl"];
您不需要将其转换为字符串并检查空值,因为文档指出:
Values read from the appSettings element of the Web.config file are always of type String. If the specified key does not exist in the Web.config file, no error occurs. Instead, an empty string is returned.
关于c# - 如何从 MVC4 中的 web.config 获取字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18483826/
我是一名优秀的程序员,十分优秀!