Web.config replacement, missing section - asp.net

I've spent a day on this 'simple' problem...
I'm using Web Deployment Projects to deploy my MVC3 webapp. I tell it to replace the appSettings section with one in a config file by entering
appSettings=Config\AppSettings.Production.config;
That works perfectly. The resulting (deployed) Web.config file has been correctly transformed and now contains the production settings I told it to use.
But, trying to do the same thing with a custom section 'spring' using exactly the same method
spring=Config\Spring.Production.config;
...I get...
web.config(1): error WDP00002: missing section spring
The spring section is at exactly the same level as the appSettings element, so I don't know why it doesn't work.
There are loads of other people with the same problem, but no satisfactory answers that I can find.

The correct syntax to reference external file is like this:
<spring configSource="Config\Spring.Production.config" />
The file="Config\AppSettings.Production.config" syntax that works with appSettings section won't work with custom sections as far as I remember, as they don't implement such property.

Related

ASP.NET MVC 5 Cannot Add Controller

all,
Just wanted to add to the body of knowledge. I was confounded, trying many solutions, when I couldn't add a controller to just one MVC project. I was getting the error:
There was an error running the selected code generator:
'The parameter is incorrect [...] '
Answer below...
It turned out to be very obvious, but since it wasted my time, here you go:
I had saved my web.config file using Save as... to another location as a backup before making changes. The project was tracking the saved copy instead of the one in the project. It looked the same in the Solution Explorer, of course. Remove, add existing, et voila.
I solved this by Excluding the Web.Config from the project and then Including it in the project
It's a simple close your web.config file(or any system file) and try again. It will work.

Kind of configuration settings can be made in XML files (web.config)?

As we know there are some config setting we can make to web.config file like mentioned at link
Now as a beginner i need to know what else we can do with this file/ i.e what else we can configure with this file in ASP.NET MVC2,3?
You can configure many other items in the web.config. However this question is not direct enough to provide an answer.
You can see the entire schema here
Web.Config is not limited to any application. Web.config can work verymuch in same way for any applications. Along with the mentioned details we can include a bunch of sections into Web.Config. some of them includes
1) If you are using any services, then service end points you can define in web.config.
2) Error/Exception handling configuraton you can define.
3) if you will use Unity, you can define Register types in config.
4) Any IIS configuratons, can overridden in web.config.
5) Any IIS Error page setup.

Web.config file not inheriting ALL parent Web.config settings (elmah)

I have a few applications that are set up using elmah for error handling. I recently read that Web.config files inherit from parent applications/directories, and decided to test it so that I can change elmah's settings in one place (since all the current Web.configs are identical when it comes to the elmah configuration). After creating a virtual directory in IIS7, nesting all my applications under it, and creating a stand-alone Web.config file in the physical folder, I tried testing it.
After removing the elmah specific configurations from one of the applications, I found that elmah stops working altogether. Just to see if it was something I did wrong, I created a connection string in the parent Web.config file, then called the connection string through code in the application. No issues. Inheritance was working fine. I tried adding all the elmah specific configurations back in, and removing them one at a time, but it kept complaining every time I removed something.
The question I have is:
Can only certain settings be inherited from the parent Web.config?
If not, am I just not comprehending how inheritance works with nested Web-configs?
I wanted to ask if it's an issue with me before I ask about it on the elmah site.
You should check this answer, it will maybe help you.
Also, in your child web.config, make sure that you do copy the configsections for Elmah (or make sure they are properly inherited). Otherwise, the elmah sections in your child web.config might not work (not entirely sure about that though)

What exactly does the staticcontent tag in the web.config file apply to?

I've been reading about the staticContent element in the web.config file but I'm having a bit of trouble figuring out exactly what ASP.Net considers static content. I assume it's going to include images, js files, css and static html files but I can't seem to find any articles that explicitly state this. Does anyone have links to documentation that explains this in detail?
I think this may be the information you're missing - Static Content MimeMap
Whilst this question is rather old and I expect Kiquenet got it sorted out none of the answers actually answer the question, I found this article looking for the answer, I expect others will to. This article answers the question:
IIS and Static content?
To paraphrase, static files are those IIS does not have a specific handler for. i.e. every file type listed in the .Net framework web.config section httpHandlers is NOT static.
Please look at Ben Swayne's most excellent answer, to quote:
You can inspect the list of file handlers in IIS by navigating to your website and then click 'Handler Mappings'. By default these are inherited from the .Net base web.config which is in a different location depending on your .Net framework version.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config
If a file being requested isn't already explicitly mapped to another handler it falls to a catch all handler (*) as the last option (System.Web.DefaultHttpHandler) which determines if it is a static file or a directory browsing request. So Static files are simply files not bound to another handler already.
As I understand it, the staticContent element in the web.config is where you can set how your site should cache it's static resource.
So as to your question of what kind of content can be specified here, it would be any file that you could benefit from caching, i.e. images, video, etc.
Also, just to provide some links I found useful:
How to configure static content cache per folder and extension in IIS7?
http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache
http://www.iis.net/configreference/system.webserver/staticcontent/mimemap says,
The <mimeMap> element of the <staticContent> element is included in the default installation of IIS 7.
IOW the list of 'static' file types is I suppose defined in the server's machine.config and/or overriden using web.config files.
You can select "Mime Types" in IIS Manager to view the list of MIME Types ... I see about 400 of these, from .323 and .aac through to .xslt and .zip, including .htm and .html but not including .aspx.

Use a dynamically generated file as configSource in web.config

Is there a way to use a generated file as a configSource for a web.config section?
In web.config, I tried a simple:
<webParts configSource="webpartsConfig.aspx" />
where webpartsConfig.aspx just spits out XML when accessed normally, but not as a configSource. (The literal source code is included as-is, giving an error.)
Any solutions or alternatives?
Motivation for this solution: I have different configuration variables locally and online, and I don't want to juggle multiple config files.
Hopefully this doesn't come too late to help, but I would suggest looking at an adaption of the source used in Enterprise Library. Details - http://blogs.msdn.com/tomholl/archive/2006/04/02/entlib2externalconfig.aspx
Then you would be creating a custom ConfigurationSource that reads HttpWebResponses.

Resources