我尝试使用这篇文章中的解决方案: How to access the folder path in web config using c# 但是我得到一个空引用异常(System.Collections.Specialized.NameValueCollection.this[string].get returned null)?
我在我的网络配置文件中有这个(它在上面链接的帖子中显示的配置中):
<appSettings>
<add key="SessionTest" value="C:\\Settings\\XmlDir\\Session\\20180824.xml"/>
</appSettings>
并像这样检索它:
string path = System.Web.Configuration.WebConfigurationManager.AppSettings["SessionTest"].ToString();
我在这里缺少什么简单的东西吗?该文件存在于文件夹中(我从文件资源管理器复制了路径,所以我无法理解导致空异常的原因>.<")
提前致谢:)
最佳答案
据我所知,这是访问 web.config
的标准方式<appSettings>
System.Configuration.ConfigurationManager.AppSettings["SessionTest"]
关于c# - 无法从 Web 配置文件访问文件夹路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52007549/