帮助在 ASP.NET 项目中拥有多个 web.config 文件
我有一个使用 web.config 文件中资源的网络项目。它包含从数据库连接到应用程序变量的所有内容。
我的应用程序中还有一个名为 /rpt 的顶级文件夹,其中存储了一些自定义报告页面。我想要一个 web.config 文件来包含此文件夹中主 web.config 文件的变体,以便 /rpt 文件夹中的文件可以使用位于 /rpt 文件夹中的这个“子”web.config 文件中的连接字符串。
所以我复制了 web.config 并将其粘贴到 /rpt 文件夹中,并删除了除连接字符串部分之外的所有内容。
然而这并没有按预期工作。我缺少什么?
这是我的 /rpt web.config 文件供参考...
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<remove name="PMISConnectionString_prod"/>
<remove name="PMISConnectionString_test"/>
<add name="ConnectionString" connectionString="Data Source=phedvsv;Initial Catalog=PM;Persist Security Info=True;User ID=IS_User;Password=ll1"/>
<add name="ConnectionString_test" connectionString="Data Source=phedvsv;Initial Catalog=PM;Persist Security Info=True;User ID=IS_User;Password=ll1"/>
</connectionStrings>
</configuration>
i have web project that uses resources in a web.config file. it contains everything from db connections to application variables.
i also have a top level folder in my application called /rpt where i store some custom reports pages. i wanted to have a web.config file to contain variations from the main web.config file in this folder such that the files in the /rpt folder can use the connection strings in this "sub" web.config file located in /rpt folder.
so i copied web.config and pasted it into the /rpt folder and deleted everything but the connection string section.
this however did not work as expected. what am i missing?
this is my /rpt web.config file for reference...
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<remove name="PMISConnectionString_prod"/>
<remove name="PMISConnectionString_test"/>
<add name="ConnectionString" connectionString="Data Source=phedvsv;Initial Catalog=PM;Persist Security Info=True;User ID=IS_User;Password=ll1"/>
<add name="ConnectionString_test" connectionString="Data Source=phedvsv;Initial Catalog=PM;Persist Security Info=True;User ID=IS_User;Password=ll1"/>
</connectionStrings>
</configuration>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个 IIS 站点只能有一个 Web.config 文件。因此,要拥有另一个,从技术上讲,您需要将文件夹 /rpt 设为 IIS 中的单独应用程序。
我能问一下你想要实现什么目标,你的问题不太清楚吗?在现有的 Web.config 中添加另一个连接字符串有什么问题?
You can only have one Web.config file per IIS site. So to have another, technically you would need to make the folder /rpt a seperate application within IIS.
Can I ask what you are trying to achieve, your question isn't really clear? What's wrong with adding another connection string to your existing Web.config?
/rpt 文件夹需要在 IIS 中创建一个应用程序,以便 asp.net 能够处理 web.config
the /rpt folder needs to be made an application in IIS for asp.net to be able to handle a web.config