简体   繁体   English

从错误的项目加载了web.config的ConfigurationFile路径

[英]ConfigurationFile path for web.config is being loaded from the wrong project

Warning: I am an IIS/ASP/Razor newb. 警告:我是IIS / ASP / Razor newb。 I am using VS2013. 我正在使用VS2013。

I have a solution with 2 web projects, let's call then Main and Methods . 我有一个包含2个Web项目的解决方案,让我们依次调用MainMethods Main is a Razor MVC project, and Methods is just a generic web project. Main是一个Razor MVC项目,而Methods只是一个通用的Web项目。 Methods references Main . Methods引用Main I am attempting to add and use connection strings to the web.config file for Methods . 我试图将连接字符串添加并使用到Methodsweb.config文件中。

However, when I attempt to access the strings in a function, they are not available. 但是,当我尝试访问函数中的字符串时,它们不可用。 I have discovered that this is probably because the web.config file that is being loaded is the one for the Main project, instead of Methods (according to AppDomain.CurrentDomain.SetupInformation.ConfigurationFile ). 我发现这可能是因为正在加载的web.config文件是Main项目的文件,而不是Methods (根据AppDomain.CurrentDomain.SetupInformation.ConfigurationFile )。

Why might this be? 为什么会这样呢?

This is because Main is the program that runs - so its the web.config that gets loaded. 这是因为Main是正在运行的程序-因此将加载web.config。 I suspect you may have the projects setup slightly wrong... 我怀疑您的项目设置可能有点错误...

Do you need two web projects? 您需要两个Web项目吗? Would Methods ever be run independently from Main - if not make Methods a Class Library , keep all your config in the web.config of Main. 方法是否可以独立于Main运行-如果不将Methods设为Class Library ,则将所有配置保留在Main的web.config中。 You will be able to reference all the config from either project (as Methods would be hosted in Main) 您将能够引用任何一个项目的所有配置(因为方法将托管在Main中)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM