ASP.Net/web.config - "The entry 'x' has already been entered"? - asp.net

In ASP.Net when I see the error message "The entry 'x' has already been entered" I think that means a name (in this case 'x') is defined twice in Web.Config.
Is that a reasonable summary of what causes that error or are there other ways it could be generated ?
The 'x' in question doesn't appear twice in the web.config - any ideas of what else could be causing this error ?

If you have nested web.config files, the same connection string entry in both web.config files can cause this error. You can fix this by adding a <clear/> tag in the nested web.config file like so:
<connectionStrings>
<clear/>
<add name="MyEntities" connectionString="blah,blah,etc." />
</connectionStrings>

It could be you have nested Web.configs. If you're running more than one application out of the same directory hierarchy you might see this. For example, say you've got IIS pointed at the root of some directory, but inside that directory is a folder with another app in it and you have a vdir pointed to that app - well you may indeed run in to this problem as ASP.Net will parse the web.config at the root first, and then the web.config for the application the vdir points to.

+1 to Erics answer. Also if you upgrade web projects (i.e. from VS 2008 to VS 2010) the web.config file it keeps for you in the backup folder will cause this error for the same reason.

I've seen this happen where the virtual directory inherited settings from the root site. Check to see if another web.config at the parent level does not also contain the AppSettings key.

Related

ASP.NET, two Web.Config

I have a .NET application with all the aspx pages and the main web.config in the root folder but I now have a situation where I need a portal like section for other users. I have created a new folder with it's own unique aspx pages and a second web.config.
I especially need a second web.config to have the <authentication> with a <forms loginUrl="" defaultUrl="> for this portal section and a <authentication> too.
I have implemeted this second web.config in the way I created the first and I am getting this error message:
It is an error to use a section registered as allowDefintion='MachineToApplication'
beyond application level. This error can be caused by a virtual directory not being
configured as an application in IIS.
Now I think the main web.config file is conflicting with the this second webconfig in it's folder. I'm not sure how to fix this, I have seen theories on how this works but no solid code.
Thank you for any suggestions and your time, it is much appreciated.
In IIS, create a virtual directory, under your main application. The local web.config will overide stuff in your main web.config, but still use you main web.config for everything else (i.e. ConnectionStrings, encoding, etc.).

Web.config in virtual directory is not overriding parent website's Web.config

I've got a website which has a virtual directory that also includes a website, and when I try to launch a page from the virtual directory, I receive an IIS 7.5 error that the name (from the connection string) is already in the collection. This wasn't a problem before I added a domain user as the Identity in the app pool. Does anyone know why this is happening? I was under the impression that sub level application's web.config overrides the parent's by default. And again, this was once working until I added a custom Identity.
The error on the page is "Parser Error Message: The entry 'dbname' has already been added."
Where the dbname is in both connection strings (i.e. parent and virtual directory). I can't delete one of the connection strings because the virtual directory is only created for test purposes, but in production it runs as its own website.
A sub web.config doesn't override a parent regardless of application. All web.configs will stack up all the way to the root of the primary application. In order for sub-application folder to make use of a connection string key that is already in use it must first be removed or all connection strings must be cleared. If you want this to be a truly stand alone application as a child add this to your connection strings:
<connectionStrings>
<clear />
<your connection string>
<connectionStrings>
If you just want to remove the single connection string use this:
<remove key="yourConnectionStringName" />
#u84six,
Today this had happened to me.
I had some websites and webservices in the same root website. The root is the default iis website (Default Web Site) and i think it was pointing to C:\Inetpub\wwwroot. Its a development environment.
After i read this answer, i found out that one of my webservices was the root website (still not sure what changed it... maybe visual studio after a migration from 2010 to 2012). That webservice was using the connectionString in conflict. I change the path back to C:\Inetpub\wwwroot\ and everything went to normal.
Maybe something similar happened to you.

Mono WebForms: Setting default page to run when starting debugging

is it possible to set a default page to run when starting debugging? In Visual Studio you can set the default page either through the context menu in Solution Explorer or in the project properties. I did not find something like that in MonoDevelop.
When I am starting debugging the browser will always navigate to the root of the application.
http://localhost:8080
Because there is no default page set in XSP for this application I get an error and always have to correct it manually.
http://localhost:8080/home.aspx
Thanks for your help.
I found a solution. I did not find the xsp.exe.config but it also works when you add the setting either globally in machine.config (residing in /etc/mono/[version]) or by creating a web.config file in your applications root. The values are comma separated.
<appSettings>
<add key="MonoServerDefaultIndexFiles" value="Home.aspx, home.aspx" />
</appSettings>
The help page http://www.mono-project.com/Config does not tell you that a appSettings section is allowed, but I think that the documentation is just incomplete. For example appSettings are used here http://www.mono-project.com/ASP.NET_Settings_Mapping#Inhibiting_the_settings_mapping too.

how can i use same web.config file for two web appliction?

I have two web application. Their folder hierarchy in server is like that.
first one is : .../firstapplitaion
second is : .../firstapplication/secondapplication/Default.aspx
At first can i run them with just firstapplication's web.config file? secondapplication's web config hasnt any special things.
Thanks for your helps..
One way would be to have a section in your web.config files point to an appropriate file, like this
<configuration>
<appSettings file="C:\MyCommonFolder\MyCommonAppSettings.config">
</appSettings>
</configuration>
Hope that helps
If the second app's web.config file is the same why bother to even run them as seperate apps? Why not just make them one app that uses the same web.config? Or were you trying to split them into seperate app pools?
What I have done in a similar situation was to have each site contain it's own seperate web.config but to move all of the shared pieces into my Machine.config. For me it's locatd in the C:\WINDOWS\Microsoft.NET\Framework\vX.X.XXX\Config folder (I would suggest backig it up first). Because of the way the config files work you can put settings in your machine.config and your websites will inherit these settigs. So put any shared settings there, with very unique names, and you should be set.

How to resolve "Server Error in '/' Application" error?

I am trying to deploy an asp.net application in our server while I am receiving the following error.
Server Error in '/' Application.
________________________________________
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
Source Error:
Line 63: ASP.NET to identify an incoming user.
Line 64: -->
Line 65: <authentication mode="Windows"/>
Line 66: <!--<forms loginUrl="~/SCR.UI/Login1.aspx"/>
Line 67: </authentication>-->
Source File: D:\BarclaysPayamentManagementSystem\scr.ui\web.config Line: 65
What is the reason and how to resolve it?
Please help
You may get this error when trying to browse an ASP.NET application.
The debug information shows that "This error can be caused by a virtual directory not being configured as an application in IIS."
However, this error occurs primarily out of two scenarios.
When you create an new web application using Visual Studio .NET, it automatically creates the virtual directory and configures it as an application. However, if you manually create the virtual directory and it is not configured as an application, then you will not be able to browse the application and may get the above error. The debug information you get as mentioned above, is applicable to this scenario.
To resolve it, right click on the virtual directory - select properties and then click on
"Create" next to the "Application" Label and the text box. It will automatically create the "application" using the virtual directory's name. Now the application can be accessed.
When you have sub-directories in your application, you can have web.config file for the sub-directory. However, there are certain properties which cannot be set in the web.config of the sub-directory such as authentication, session state (you may see that the error message shows the line number where the authentication or session state is declared in the web.config of the sub-directory). The reason is, these settings cannot be overridden at the sub-directory level unless the sub-directory is also configured as an application (as mentioned in the above point).
Mostly, we have the practice of adding web.config in the sub-directory if we want to protect access to the sub-directory files (say, the directory is admin and we wish to protect the admin pages from unauthorized users).
I had this error when the .NET version was wrong - make sure the site is configured to the one you need.
See aspnet_regiis.exe for details.
I had this error with VS 2015, in my case going to the project properties page, Web tab, and clicking on Create Virtual Directory button in Servers section solved it
It sounds like the admin has locked the "authentication" node of the web.config, which one can do in the global web.config pretty easily. Or, in a nutshell, this is working as designed.
I just had the same issue on visual studio 2012. For a internet application project.
How to resolve “Server Error in '/' Application” error?
Searching for answer I came across this post, but none of these answer help me.
Than I found another post here on stackoverflow that has the answer for resolving this issue.
Specified argument was out of the range of valid values. Parameter name: site
When you create an new web application using visual studio.net, it automatically creates the virtual directory and configures it as an application. However, if you manually create the virtual directory and it is not configured as an application, then you will not be able to browse the application and may get the above error.
I also got this error when I moved an entity framework edmx file into a "Models" sub-folder. This automatically changed the metadata in my connection string setting in my app.config.
So before the connection string changed... it looked something like this:
<connectionStrings>
<add name="MyDbEntities" connectionString="metadata=res://*/MyDb.csdl|res://*/MyDb.ssdl|res://*/MyDb.msl; ...
</connectionStrings>
And after... it added the "Models" subfolder name (btw... it also added "Models" to the namespace for the EF classes generated) and the connection string now looks something like this:
<connectionStrings>
<add name="MyDbEntities" connectionString="metadata=res://*/Models.MyDb.csdl|res://*/Models.MyDb.ssdl|res://*/Models.MyDb.msl; ...
</connectionStrings>
I have a website project that references this Entity Framework DB project. But its web.config did not have the updates to the connection string... and that's when I started getting the compilation error being discussed here.
To fix this error, I updated the connection string in the web.config in the website project to match the app.config in my EntityFramework project.
vs2017 just added in these lines to csproj.user file
<IISExpressAnonymousAuthentication>enabled</IISExpressAnonymousAuthentication>
<IISExpressWindowsAuthentication>enabled</IISExpressWindowsAuthentication>
<IISExpressUseClassicPipelineMode>false</IISExpressUseClassicPipelineMode>
with these lines in Web.config
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="1048576" />
<identity impersonate="false" />
<authentication mode="Windows" />
<authorization>
<allow users="yourNTusername" />
<deny users="?" />
</authorization>
And it worked
I opened the Properties window for the website project in question and changed Windows Authentication to "Enabled" and that resolved my issue in VS 2019.
The error message is quite clear: you have a configuration element in a web.config file in a subfolder of your web app that is not allowed at that level - OR you forgot to configure your web application as IIS application.
Example: you try to override application level settings like forms authentication parameters in a web.config in a subfolder of your application

Resources