web.config size limit – Overcome IIS 500.19 error

Hi everyone, today I’d like to share an experience I had on a production server. At the beggning I though the problem was related with a SharePoint server, indeed it was related with SharePoint, but in this case to be more precise, with IIS.

We were updating some solutions in SharePoint that adds configuration to the web.config file of SharePoint, but when we tried to refresh the site homepage to test the configuration made, we got a 500 error
In this case, the web.config file size was exceeding the limits. Indeed, by design a web.config file should not exceed 250kb. From there, two solutions could be chosen to solve this issue, ang get access back to our website.

So to solve this problem, the solution is to modify the size configured by design for a web.config file in the registry. To do so, open your registry by typing regedit in windows start menu, and find the following key:
Create a new key named “Configuration”, and a DWORD value named “MaxWebConfigFileSizeInKB”. Change the value of this DWORD to match your requirement. For example, I set 2048 in decimal, which translates to 0x00000800 ib hexadecimal.

To refresh this changes, is it necessary to open an administrator CMD and type iisreset, once the web is refreshed you will be able to access again.

Alternative solution

If you don’t want to add registry entries in your server, there is another solution that allows to split the web.config file in several files.

In this case, you will have a main web.config file in which you’ll reference sub config files by adding a configSource attribute onto the sections you would like to split into other files.

To illustrate this, if you’d like to split the section “appsettings” in another file, you would change the appSettings section in your web.config file to :

  appSettings configSource="appsettings.config"

So, you will need to add all your appsettings entries like they were in the original web.config file, for example :

add key="aspnet:RestrictXmlControls" value="true"
add key="FeedCacheTime" value="300"
add key="FeedPageUrl" value="/_layouts/15/feed.aspx?"
add key="FeedXsl1" value="/Style Library/Xsl Style Sheets/Rss.xsl"
add key="aspnet:AllowAnonymousImpersonation" value="true"

So, after doing this, you’ll have two files (web.config and appsettings.config) in the inetpub folder, so remember that you will need to modify each on of the files, and in case you need to do some configuration changes to do an iisreset to deploy the changes to the webapp.

Hope it helps someone!

Cleanup IIS Log files on SharePoint

A common problem I see in many of our customers environments is that their SharePoint servers will start to run lower on disk space on the C: drive after being up and running for a while. Asides from the typical growth due to patching the customers have reported that there have been no other changes or software installations done on the servers. If you have built the system partition based on Microsoft’s recommendations of a minimum of 80GB then you wont be getting low for some time, however even seeing a disk starting to drop 5-10GB faster then you expect can cause some alarm.

What I find to be the case more times then not is that they have either not moved the SharePoint logs from the C: partition or they have not setup any type of job to purge the IIS logs. These logs can grow faster then you might think and when you have multiple web applications this just speeds things up further.

There is a quick way to fix this using a few lines of PowerShell code. This method I am outlining does not do any type of archival of the logs. If this is needed some additional code can be added to this to achieve without a tremendous amount of effort. The goal of this is a quick way to purge the logs and regain space. This is particularly useful in dev and QA environments where no historical data is required.

Take the code below and paste it into a text file and save with a .ps1 extension. This script will go through all sub folders below the LogFiles directory and clean up the log files.

get-childitem -Path C:inetpublogsLogFiles -recurse | where-object {$_.lastwritetime -lt (get-date).addDays(-7)} | Foreach-Object { del $_.FullName }

Once saved you can then create a new scheduled task that will call this script on the desired interval to purge your IIS logs and reclaim storage. To change the time the log files are kept you just need to change the number value in the script to the desired number of days.

Another simple solution is to disable the IIS logging, to do this, you have to do the following:

  1. Open IIS Manager and navigate to the level you want to manage. For information about opening IIS Manager.
  2. In Features View, double-click Logging.
  3. On the Logging page, in the Actions pane, click Enable to enable logging or click Disable to disable logging.

That’s all, hope it helps!!