Thursday, January 30, 2014

Asp Net config, automatically disable debug on production servers using a nice feature on machine.config

Developing in hurry is not the best thing to do but we all have to.
One of the things that I usually forgot to change in production is turning off the debug mode on web.config
So i forget to change:
<compilation debug ="true">
to
<compilation debug ="false">

So why leaving debug to true is so bad?
  • Compilation takes longer as batch optimizations are disabled 
  • Scripts and images from WebResources.axd will not be cached on the client 
  • Larger memory footprint 
  • Code will execute slower because of enabled debug paths
And you have to multiply for each site you are deplyoing in the same server.
This means wasting more memory, and having sites running much slower.
And you often cannot check every single web.config to see if the settings are right.

When deploying ASP.NET applications to a production environment, to force debug = false in all ASP.NET applications on the server, you can change the retail switch in machine.config:

<configuration>
    <system.web>
        <deployment retail="true" />
    </system.web>
</configuration>

This will also disable page output trace and force custom error pages.
This can be great generally, but can turn in a nightmare if you have a site that does not run properly since you have custom errors always on.
Solutions can be:
  • look at event log of server
  • install an aspnet logger like elmah
  • try debug locally
  • set retail to false for a while (not recommended because causes rebuild of all sites)
Have a nice day folks!

Submit this story to DotNetKicks