can I load a configSource and then add additional keys in web.config - iis

I have some individual settings I need to apply to specific web sites, and I have a slew of settings that are shared across the websites. I deploy via a continuous integration system.
In my web.config file I have :
<appSettings configSource="App_Data\thisSiteSettings.xml" >
<clear />
<add key="AllSitesSetting" value="ForAllSites" />
</appSettings >
What happens is I get just the settings from thisSiteSettings.xml, and none of the settings from the web.config. I also tried having 2 sections:
<appSettings >
<clear />
<add key="AllSitesSetting" value="ForAllSites" />
</appSettings >
<appSettings configSource="App_Data\thisSiteSettings.xml" >
</appSettings >
which just threw an Error. Finally I tried including the configsource as an "add" node, but that just threw an error as well. (<add configSource="thisSiteSettings.xml" />)
How can I load a few site specific app settings from a seperate file, and the rest from the web.config file?

You can use
<appSettings file="thisSiteSettings.xml">
...
<appSettings />
appSettings in the external file will override settings with the same key in the main configuration file.

Related

Adding new handler to the web.config

I am developing a custom web application and try to change the default file extensions used to serve the webpages, I want to register new handler in the web.config so the user can request the pages with new extension: *.do
I am editing the web.config directly because I want to automate the procedure with powershell next.
.......
According to your description, I suggest you could add below web.config try to use below config setting.
<handlers>
<add name="SampleHandler" verb="*"
path="*.do"
type="SampleHandler, SampleHandlerAssembly"
resourceType="Unspecified" />
</handlers>
More details, you could refer to below article:
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/handlers/add

Remove duplicate files from IIS for same application

I have X the same applications in IIS(some code/exe, but different config file).
Would it be possible to put duplicate files to some folder?
For example I have applications:
Canada.weather.com
usa.weather.com
mexico.weather.com
Uses same .dll and .exe, but have different config.
As Lex says, we don't suggest you to put duplicate files to some folder. If one of the dll is missed or not, it will make all the sites down.
If you still want to do this , you could apply the setting in applicationHost.config and wrapping it in a tag.
The applicationhost.config file path :
%windir%\system32\inetsrv\config\applicationHost.config
Each sites will have its own location, you could add the custome configuration inside each location tag.
Like belowl, I enable the windows auth for "BrandoTestSite":
<location path="BrandoTestSite">
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true" />
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
</location>
Notice: This way is lower maintainability. We don't suggest you choose this way to manage mutiple application.

IIS 7.5 = Nested web.config will not override custom error handling set in application level web.config

Running ColdFusion 11 (Update 7) and IIS 7.5
My site application/root level web.config:
<configuration>
<system.webServer>
<httpErrors errorMode="Custom" />
</system.webServer>
</configuration>
My nested web.config file, which sits inside /api/eb :
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>
When I visit a page that sits within the /api/eb sub-directory (e.g. 401.cfm) and trigger a 401 status code the server will return the Custom error handler response. My interpretation from the docs is that the nested web.config file should override the root web.config file but it clearly is not.
I've checked within the IIS applicationhost file and httpErrors overrideModeDefault is set to true. I also tried using a location tag within my root web.config file to do the same thing but it is also ignored unless I set the path to the wildcard character.
I'm out of ideas. Your help will be greatly appreciated. Thank you in advance.
I found this article which seems to explain your question pretty well - How to Use HTTP Detailed Errors in IIS 7.0
Specifically this excerpt:
Security Considerations
A word of caution: For architectural reasons, IIS can only execute the URL if it is located in the same Application Pool. Use the redirect feature to execute a Custom Error in a different Application Pool.
IIS can also return a 302 Redirect to the browser when a particular error occurs. Redirect is good if you have a server farm. For instance, you can redirect all your errors to a central location that you closely monitor.
There is risk however: responseMode="File" (which is the default) allows you to specify every file on the disk. This will not work if you are very security conscious.
A workable scenario might include only allowing the delegation of the errorMode setting. This enables a developer to receive Detailed Errors for his application even if he is using a remote client. All that is necessary is to set errorMode="Detailed". Here is how to configure this scenario:
Allow the delegation of the httpErrors section:
<section name="httpErrors" overrideModeDefault="Allow" />
Second, go to the section in applicationHost.config and change it so that only errorMode is delegated:
<httpErrors lockAllAttributesExcept="errorMode" lockElements="error">
<error statusCode="404" prefixLanguageFilePath="E:\inetpub\custerr" path="404.htm" />
<error statusCode="401" prefixLanguageFilePath="E:\inetpub\custerr" path="401.htm" />
<error statusCode="403" prefixLanguageFilePath="E:\inetpub\custerr" path="403.htm" />
<error statusCode="405" prefixLanguageFilePath="E:\inetpub\custerr" path="405.htm" />
<error statusCode="406" prefixLanguageFilePath="E:\inetpub\custerr" path="406.htm" />
<error statusCode="412" prefixLanguageFilePath="E:\inetpub\custerr" path="412.htm" />
<error statusCode="500" prefixLanguageFilePath="E:\inetpub\custerr" path="500.htm" />
<error statusCode="501" prefixLanguageFilePath="E:\inetpub\custerr" path="501.htm" />
<error statusCode="502" prefixLanguageFilePath="E:\inetpub\custerr" path="502.htm" />
</httpErrors>
Notice that the correct value for the overrideModeDefault attribute is Allow, not true as you mentioned in your question.
This article further explains the overrideModeDefault attribute - Understanding IIS 7.0 Configuration Delegation
Excerpt:
The overrideModeDefault attribute is an optional attribute that defines the locked state of a section. Its available values are either Allow or Deny. The default value is "Allow". All IIS sections that are related to any performance, security or critical aspect of the server are locked with this attribute set to "Deny". If the overrideModeDefault attribute is set to "Deny", then any configuration files at a lower level (i.e. web.config files) that set a value for a property for the specific configuration section are not able to take effect and override the global values. This incurs in a lock violation and an error occurs.

Enable Compression Mime-types for Web-Site Application

Our website uses both dynamic and static compression. I know that compression can be enabled/disabled on a web.config level, but that the mime-types for static and dynamic compression cannot be enabled at a web-config level.
Meaning, this section:
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" staticCompressionIgnoreHitFrequency="true">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<staticTypes>
Stuff
</staticTypes>
<dynamicTypes>
Stuff
</dynamicTypes>
</httpCompression>
Must go in the applicationHost.config, and is generally edited using appcmd.exe.
I know there is a location element in the applicationHost.config that allows setting many things on a per website basis, but I can't seem to find anywhere if mimetypes for dynamic compression are one of them.
I have tried overriding these settings using a location element, but have not had any success and cannot find documentation stating it's possible for the httpCompression element.
To make matters worse, we install our product as a web application under the default site, so really we want to enable these dynamic compression mime-types only under our application, instead of site (or server) wide. Is this possible?
Generally, we are using IIS 7 and above. Right now our minimum is 7, so assume anything needs to work with that.
My question is:
Can httpCompression settings be set in the applicationHost.config per website and possible per web application under a web site?
Is there a different way to enable dynamicCompression specifics on a website/web application level?
Just an important precision: There is one prerequisite to ensure that you can add MIME Types in the "web.config" file:
It is possible to add MIME Types in the <staticTypes> and <dynamicTypes> sections at the website level (in "web.config") only if this is explicitely allowed at the "applicationHost.config" level, as explained in this solution from Stack Overflow:
The important thing to note is that modifying your
applicationHost.config (in %windir%\system32\inetsrv\config) from the following setting:
<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
to:
<section name="httpCompression" overrideModeDefault="Allow" />
will enable configuration of the httpCompression tag under the
system.webServer tag in your web.config.
Yes you can very well add dynamic and static types in web application's web.config file. ApplicationHost.config will define global compression settings and if you want to override them in your application you can do so. Following is sample from one of my application.
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
<add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" preCondition="integratedMode" />
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="Glimpse" path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" preCondition="integratedMode" />
</handlers>
<httpCompression>
<dynamicTypes>
<remove mimeType="text/*" />
<add mimeType="application/json" enabled="true" />
</dynamicTypes>
</httpCompression>
Here remove tag in dynamicTypes removes global entry coming from ApplicationHost.config
add tag is adding additional mimeType on top of global entries from applicationHost.config. This addition will be applicable only for whose web.config is being modified.
Similarly you can modify staticTypes as well.

Disable pool recycling on Azure Websites

I have a website deployed on Azure Websites and I want to disable pool recycling.
If you have a regular IIS installation, you can disable this in application pool advanced settings by setting "Recycling -> Disable overlapped recycle" to true.
Yet I can't seem to find this option in the azure management console, nor do I find any information on this subject online.
Any pointers would be greatly appreciated!
Thanks a lot Puneet Gupta for pointing me in the right direction!
I couldn't use the exact solution, but it set me on the right path.
Here's how I solved this:
1) Get your hands on the applicationHost.config.
The easiest way is going through the SCM Console via "files" and then follow the links in json.
In the end, you end up here: https://YOUR_WEBSITE_NAME.scm.azurewebsites.net/api/vfs/LocalSiteRoot/Config/applicationhost.config
2) Identify the current status of overlapped recycle.
In the applicationHost.config file, look for the "applicationPools" element
It should look like this:
<applicationPools>
<add name="YOUR_SITE_NAME" managedRuntimeVersion="v4.0">
<processModel identityType="ApplicationPoolIdentity" />
</add>
<add name="~1YOUR_SITE_NAME" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated">
<processModel identityType="ApplicationPoolIdentity" />
</add>
</applicationPools>
If you see this, then overlapped recycle is ENABLED!
You can't write directly to this file but fortunately microsoft gives us the power to transform it!
3) Transform it!
You can transform the applicationHost.config file by placing an applicationHost.xdt file in the /site directory of your website (mind you that the website itself is deployed in the /site/wwwroot directory, so your applicationHost.xdt transform must reside in the parent folder of where your website is.
If you want to disable overlapped recycle, then this is what you put in the file:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">>
<system.applicationHost>
<applicationPools>
<add name="YOUR_SITE_NAME" xdt:Locator="Match(name)">
<recycling disallowOverlappingRotation="true" xdt:Transform="Insert" />
</add>
<add name="~1YOUR_SITE_NAMEd" xdt:Locator="Match(name)">
<recycling disallowOverlappingRotation="true" xdt:Transform="Insert" />
</add>
</applicationPools>
</system.applicationHost>
</configuration>
4) restart the site
finally you need to restart your site to have your transformations applied.
After restart, go to step 1 again and you should now see this instead:
<applicationPools>
<add name="YOUR_SITE_NAME" managedRuntimeVersion="v4.0">
<processModel identityType="ApplicationPoolIdentity" />
<recycling disallowOverlappingRotation="true" />
</add>
<add name="~1YOUR_SITE_NAME" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated">
<processModel identityType="ApplicationPoolIdentity" />
<recycling disallowOverlappingRotation="true" />
</add>
</applicationPools>
et voila: overlapped recycle is now disabled on your azure website.
You will have to use a XDT transform similar to the one mentioned in https://github.com/projectkudu/kudu/wiki/Xdt-transform-samples#remove-all-your-recycling-options-from-your-net-4-application-pool-and-make-it-available-always.
More details on using transforms is in http://blogs.msdn.com/b/waws/archive/2014/06/17/transform-your-microsoft-azure-web-site.aspx

Resources