系统.配置 web.config 和 app.config
在使用第三方 dll 时,我遇到以下异常:
不在独立 exe 中运行时必须指定 exePath
当不在具有以下跟踪的
System.Configuration.ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath)。
我发现的原因是它正在寻找app.config,而我已经在web.config中提供了详细信息。我的问题是:为什么 system.configuration 会区分 web.config 和 app.config?有什么想法吗?
While using a third party dll I was getting the following exception:
exePath must be specified when not running inside a stand alone exe
with the following trace
System.Configuration.ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath).
The reason I found was that it was looking for app.config and I had provided the details in web.config. My question is: why does the system.configuration differentiate between web.config and app.config? Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可执行文件:
多个.NET可执行文件可以位于同一目录中。由于同一目录中不能有两个同名的文件,因此应用程序的主配置文件必须使用不同的名称。
applicationName.exe.config
方案解决了这个问题。Web 应用程序/站点:
.NET Web 应用程序被编译为 DLL,而网站通常是即时编译的。因此,这些类型的项目不存在“主要切入点”。可以创建一个 Web 项目,其中每个页面都编译为自己的程序集。哪一个是主要组件?我们应该以哪个程序集命名配置文件?
幸运的是,单个目录只能托管一个 Web 项目,因此这里只存在一个主配置文件。这允许按照约定选择主配置文件名,并且该文件名恰好是
web.config
。Executables:
Several .NET executables can live in the same directory. As there cannot be two files with the same name in the same directory, the applications must use different names for their main configuration files. The
applicationName.exe.config
scheme solves this.Web applications / sites:
.NET web applications are compiled to DLLs, and web sites are usually compiled just-in-time. Hence, there is no "main entry point" in these types of projects. It is possible to create a web project where each page is compiled to its own assembly. Which one is the main assembly? Which assembly should we name the configuration file after?
Fortunately, only one web project can be hosted from a single directory, so only one main configuration file is going to live here. This allows for the main configuration file name to be picked by convention, and that file name happens to be
web.config
.web.config
仅适用于您的网站和 Web 应用程序。它保持固定,即不改变其名称;它总是被称为web.config
。app.config
用于非 Web 应用程序 - Winforms、WPF、NT Services 等。当您构建项目时,它将被重命名为YourApplicationName.exe.config
。您永远不会在应用程序的目录中找到具有该名称的app.config
(或者即使找到,也不会使用它)。为什么 Microsoft 选择使用两种不同类型的名称 - 我不知道 - 请询问 Microsoft。
因此,您基本上只需要知道您正在处理什么并在正确的位置提供信息即可。
web.config
is for your website and web applications only. It stays fixed, i.e. doesn't change its name; it's always calledweb.config
.app.config
is for non-web applications - Winforms, WPF, NT Services etc. This will be renamed intoYourApplicationName.exe.config
when you build your project. You won't ever find anapp.config
by that name in an application's directory (or if you do, it will not be used).Why Microsoft choose to use two different kind of names - I don't know - ask Microsoft.
So you basically just have to know what you're dealing with and provide the information in the correct place.