无法读取web.config文件 [英] Can not read web.config file

查看:302
本文介绍了无法读取web.config文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们尝试读取配置文件中的连接字符串时,我们收到错误。这就是我读取配置文件的方式:

We are getting an error when we try to read the connection string in the config file. This is how I read the config file:

 ConfigurationManager.ConnectionStrings[connectionStringName];

以下是错误。
虚拟路径'/ site1'映射到另一个应用程序,这是不允许的。

Below is the Error. The virtual path '/site1' maps to another application, which is not allowed.

最后,这是我在IIS服务器中的站点结构。请注意,三个子网站位于主网站下。

Finally, this is my site structure in IIS server. Please note that the three sub web site are hosted under the main Web site.

注意:此错误并非总是发生。有时,所有网站都可以正常工作,没有任何问题。此外,三个子网站引用相同的代码库。

Note: This error is not always occurring. Sometimes all the web sites works fine without any issues. Also the three sub websites refer to same code base.

以下是完整的跟踪日志:

Below is the complete trace log:

     The following exception was thrown: The virtual path '/site1' maps to another application, which is not allowed.. Exception details: System.ArgumentException: The virtual path '/site1' maps to another application, which is not allowed. 
   at System.Web.CachedPathData.GetVirtualPathData(VirtualPath virtualPath, Boolean permitPathsOutsideApp) 
   at System.Web.HttpContext.GetFilePathData() 
   at System.Web.HttpContext.GetSection(String sectionName) 
   at System.Configuration.ConfigurationManager.GetSection(String sectionName) 
   at System.Configuration.ConfigurationManager.get_ConnectionStrings() 

我似乎在以下地方也有这个问题:

I seem to have this issue in the following place as well:

   The following exception was thrown: The virtual path '/site1' maps to another application, which is not allowed.. Exception details: System.ArgumentException: The virtual path '/site1' maps to another application, which is not allowed. 
   at System.Web.CachedPathData.GetVirtualPathData(VirtualPath virtualPath, Boolean permitPathsOutsideApp) 
   at System.Web.HttpContext.GetFilePathData() 
   at System.Web.HttpContext.GetSection(String sectionName) 
   at System.ServiceModel.Activation.HostedAspNetEnvironment.UnsafeGetSectionFromWebConfigurationManager(String sectionPath, String virtualPath) 
   at System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetSectionNoTrace(String sectionPath) 
   at System.ServiceModel.Diagnostics.TraceUtility.SetEtwProviderId() 
   at System.ServiceModel.ChannelFactory..ctor() 
   at System.ServiceModel.ChannelFactory`1..ctor(Type channelType) 
   at System.ServiceModel.ChannelFactory`1..ctor(Binding binding, EndpointAddress remoteAddress) 
   at System.ServiceModel.ClientBase`1..ctor(Binding binding, EndpointAddress remoteAddress) 

这似乎发生在系统尝试读取Web服务时设置。

This seems to occur when the system tries to read the web service settings.

推荐答案

如果IIS_IUsers组无法编辑当前应用程序根目录中的文件,则会发生这种情况您尝试访问配置的文件夹。

This can occur if the "IIS_IUsers" group doesn't have the right to edit files in the current app root folder for which you are trying to access the config.

根据问题中给出的代码行,这应该默认为当前应用程序的配置。
检查IIS是否在允许其访问文件系统的帐户下运行(类似于localsystem或networkservice应该这样做)然后在IIS中检查正在运行的应用程序正在运行的应用程序池的帐户是否正在运行在具有相同权限的帐户下或在使用IIS权限的applicationpoolidentity下。

based on the line of code given in the question this should default to the config for the current application. Check that IIS is running under an account that allows it access to the file system (something like localsystem or networkservice should do) then within IIS check that the account for the application pool under which the apps in question are running is running under an account with the same permissions or under "applicationpoolidentity" which uses IIS's permissions.

作为一个临时测试,您可以将所有人完全控制权交给相关目录,然后删除该权限并添加其他权限,直到您满意它只与您合作需要。

As a temporary test you can grant "everyone" full control to the directories in question, then remove that permission and add others until you are happy it's working with only what you need.

这篇关于无法读取web.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆