1

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];

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

Finally, this is my site structure in IIS server. Please note that the three sub websites are hosted under the main Web site. enter image description here

Note: This error is not always occurring. Sometimes all the websites work fine without any issues. Also, the three sub websites refer to the 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) 

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

wp78de
  • 18,207
  • 7
  • 43
  • 71
user1659922
  • 346
  • 4
  • 15
  • 3
    From which site you are trying to read the configuration? – Chetan Aug 16 '17 at 11:57
  • For all three web sites I.m getting same error – user1659922 Aug 16 '17 at 12:04
  • 3
    can you show us inside your web.config file and expand one of those web applications in the IIS screenshot please. – Craig Aug 16 '17 at 14:31
  • 1
    Do you do any kind of config transform? Do all the different virtuals use the same config? – HerSta Aug 18 '17 at 11:43
  • 1
    Have you seen this [post](https://stackoverflow.com/questions/19277350/asp-net-virtual-path-maps-to-another-application-which-is-not-allowed) which talks about issue with copying a web site ? – Subbu Aug 18 '17 at 13:43
  • @HerSta Yes all applications points to same physical directory. So all use same config – user1659922 Aug 18 '17 at 14:06
  • @Subbu Only change i did was adding 2 new applications and point them to already existing applications physical directory. Before adding new applications everything worked fine. – user1659922 Aug 18 '17 at 14:13
  • 1
    Are they set up as virtual directories in IIS? – C. Helling Aug 18 '17 at 18:27
  • @C.Helling No as virtual applications – user1659922 Aug 19 '17 at 05:08
  • When an ASP.NET Web Site is copied to a new folder the setting associated with the solution's "Virtual Path" property is often set to the folder name and not the root. Change the Virtual Path setting from the folder name to "/": Solution->Properties->Virtual Path-> Change to "/" – wp78de Aug 20 '17 at 02:21
  • If you want to use the same codebase for different websites, then you would be better off by creating three separate websites in place of three applications within the same website. – TejSoft Aug 21 '17 at 01:30
  • 1
    Why do you need 3 apps with the same codebase on the same machine? If you need users to access you app using different routes there are better ways to do it – Alexander Mokin Aug 23 '17 at 22:58

4 Answers4

0

When an ASP.NET Web Site is copied to a new folder often the solution's "Virtual Path" property is set to the folder name and not the root. Change the Virtual Path setting to "/" to resolve this issue. This can be done by right click the project, opening the properties dialog: Solution->Properties->Virtual Path-> Change to "/"

wp78de
  • 18,207
  • 7
  • 43
  • 71
0

Try running each site under its own application pool and use a seperate bin directory for each site including the main site. IIS might think it's serving Main but somewhere in memory it switched to Site1. Use WCF to communicate between sites if necessary.

davidlbaileysr
  • 644
  • 6
  • 6
0

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.

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.

War
  • 8,539
  • 4
  • 46
  • 98
0

You have an error in your applicationhost.config file.

You have to check that each <application> path attribute is unique for a <site> !

To do so :

Open %userprofile%\My Documents\IISExpress\config\applicationhost.config and in the section <sites> check the <virtualDirectory> node of the appropriate <site>. You can easily find it from its port number which reside in the <bindings>/<binding> bindingInformation attribute.

E.g. :

<site name="MyWebSite" id="1234">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="c:\inetpub" />
    </application>
    <application path="/subsite1" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Solution\subsite1" />
    </application>
    <application path="/subsite2" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Solution\subsite2" />
    </application>
    <application path="/subsite3" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Solution\subsite3" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:1234:localhost" />
    </bindings>
</site>  

As you can see in this example, each application path is unique.

John-Philip
  • 3,392
  • 2
  • 23
  • 52