gpt4 book ai didi

.net - 查找当前配置文件的名称

转载 作者:行者123 更新时间:2023-12-04 05:35:07 26 4
gpt4 key购买 nike

有没有办法从类库中找到当前应用程序配置文件的名称(和路径)?

例如。在网络应用程序中,这将是 web.config ,在 Windows 应用程序或服务中,这将是 myapp.exe.config .

最佳答案

尝试这个:

AppDomain.CurrentDomain.SetupInformation.ConfigurationFile

如果这不起作用,请添加对 System.Web 和 System.Configuration 的引用,然后尝试以下操作:
if(HttpRuntime.AppDomainAppVirtualPath  == null) 
return ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath;
else
return VirtualPathUtility.ToAbsolute("~/Web.config");

关于.net - 查找当前配置文件的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2617327/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com