{"id":144,"date":"2016-03-11T14:57:28","date_gmt":"2016-03-11T13:57:28","guid":{"rendered":"http:\/\/blogs.msdn.microsoft.com\/lavanack\/?p=144"},"modified":"2022-05-30T13:50:17","modified_gmt":"2022-05-30T11:50:17","slug":"aspnet-debugmode","status":"publish","type":"post","link":"https:\/\/laurentvanacker.com\/index.php\/2016\/03\/11\/aspnet-debugmode\/","title":{"rendered":"Lister vos applications ASP.Net en mode debug avec PowerShell \/ List all your ASP.Net applications in debug mode with PowerShell"},"content":{"rendered":"<div id=\"fr-FR\"><a href=\"#en-US\">English version<\/a><\/div>\n<p>[MAJ : 27\/06\/2019] Ajout du code PowerShell pour d\u00e9sactiver le mode debug sur toutes les applications<\/p>\n<p>D&rsquo;exp\u00e9rience je peux assurer que la moiti\u00e9 des clients ont au moins une application ASP.Net qui tournent en mode debug en production (J&rsquo;avoue que d\u00e9busquer une telle application est devenu un de mes jeux pr\u00e9f\u00e9r\u00e9s lors de mes visites chez mes clients). Je ne reviendrai pas sur les effets n\u00e9fastes du mode debug car ces informations sont facilement trouvables sur Internet (Je vous mets quand m\u00eame quelques liens en bas de cet article). Le but de ce court article c&rsquo;est de vous expliquer via une simple ligne de commandes PowerShell, comment lister toutes vos applications et le mode debug associ\u00e9 :<\/p>\n<div id=\"scid:9D7513F9-C04C-4721-824A-2B34F0212519:220751ca-ee58-4584-a938-3d1d7a5bb624\" class=\"wlWriterEditableSmartContent\" style=\"float: none; margin: 0px; padding: 0px;\">\n<pre class=\"brush: powershell; collapse: true; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n# This line is only Required for PowerShell 2.0 \r\nImport-Module WebAdministration \r\nGet-WebConfiguration system.web\/compilation -Recurse | Select @{Name=&quot;ComputerName&quot;;Expression={$env:computername}}, @{Name=&quot;SiteName&quot;;Expression={$_.PSPath.replace(&quot;MACHINE\/WEBROOT\/APPHOST&quot;, &quot;&quot;).TrimStart(&quot;\/&quot;)}}, Debug\r\n<\/pre>\n<p>Supposons que nous h\u00e9bergions deux sites web sur le serveur W2K12R2_IIS001 : www.contoso.com et www.northwindtraders.com :<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"149\" class=\" size-medium wp-image-164 aligncenter\" src=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/03\/IIS-300x149.jpg\" alt=\"IIS\" srcset=\"https:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/03\/IIS-300x149.jpg 300w, https:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/03\/IIS.jpg 367w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>la commande revoit le r\u00e9sultat suivant :<\/p>\n<p><img decoding=\"async\" class=\" aligncenter\" src=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/03\/debug.jpg\" alt=\"debug\" \/><br \/>\nOn constate que le site www.contoso.com est effectivement en mode debug (ce qui n&rsquo;est pas une bonne pratique sur un environnement de production). Quid du site www.northwindtraders.com ? En r\u00e9alit\u00e9 ce site n&rsquo;est pas list\u00e9 ici car il h\u00e9rite de la configuration par d\u00e9faut \u00e0 savoir <strong>&lt;compilation debug=\u201cfalse\u201d \/&gt;<\/strong> .Si jamais vous voyez appara\u00eetre\u00a0 une sortie similaire \u00e0 celle-ci :<\/p>\n<p><a href=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/03\/debug2.jpg\"><img decoding=\"async\" class=\" aligncenter\" src=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/03\/debug2.jpg\" alt=\"debug2\" \/><\/a><\/p>\n<p>C&rsquo;est que le mode <b>&lt;compilation debug=\u201cfalse\u201d \/&gt;<\/b><b>\u00a0<\/b>a<b> <\/b>explicitement \u00e9t\u00e9 valoris\u00e9 dans le fichier de configuration (par d\u00e9faut le web.config \u00e0 la racine du site).<\/p>\n<p>Si vous souhaitez d\u00e9sactiver toutes les applications en mode debug en une fois, vous pouvez le faire via une simple ligne de commandes PowerShell\u00a0 (Attention au recyclage que cela va provoquer toutefois):<\/p>\n<pre class=\"brush: powershell; collapse: true; light: false; title: ; toolbar: true; notranslate\" title=\"\"> \r\n# This line is only Required for PowerShell 2.0 \r\nImport-Module WebAdministration \r\nGet-WebConfiguration system.web\/compilation -Recurse | Where-Object -FilterScript {$_.Debug} | ForEach-Object -Process { Set-WebConfigurationProperty -pspath $_.PSPath -filter &quot;system.web\/compilation&quot; -name &quot;debug&quot; -value &quot;False&quot; -Verbose }\r\n<\/pre>\n<p>Quelques liens utiles sur le mode debug (et comment le d\u00e9sactiver) :<\/p>\n<ul>\n<li>deployment retail=\u201ctrue\u201d pour ASP.NET : <a href=\"https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/sbovo\/deployment-retailtrue-pour-asp-net\">https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/sbovo\/deployment-retailtrue-pour-asp-net<\/a><\/li>\n<li>ASP.NET Memory: If your application is in production\u2026 then why is debug=true : <a href=\"https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/tess\/asp-net-memory-if-your-application-is-in-production-then-why-is-debugtrue\">https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/tess\/asp-net-memory-if-your-application-is-in-production-then-why-is-debugtrue<\/a><\/li>\n<li>HOW TO: Disable Debugging for ASP.NET Applications : <a href=\"http:\/\/support.microsoft.com\/kb\/815157\/en-us\">http:\/\/support.microsoft.com\/kb\/815157\/en-us <\/a><\/li>\n<li>Why I am not able Turn Off CustomErrors? <a href=\"https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/tess\/asp-net-memory-if-your-application-is-in-production-then-why-is-debugtrue\">https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/webtopics\/why-i-am-not-able-turn-off-customerrors<\/a><br \/>\nDeploymentSection.Retail Property : <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.web.configuration.deploymentsection.retail.aspx\">https:\/\/msdn.microsoft.com\/en-us\/library\/system.web.configuration.deploymentsection.retail.aspx <\/a><\/li>\n<\/ul>\n<hr \/>\n<div id=\"en-US\"><a href=\"#fr-FR\">Version fran\u00e7aise<\/a><\/div>\n<p>[update : 08\/21\/2020] Added PowerShell code to disable debug mode on all applications<\/p>\n<p>From own experience I can tell that half the customers have at least an ASP.Net application running in debug mode in their production environment (I admit that flushing out such an application has become one of my favorite games during my customer visits). I will not dwell on the negative effects of debug mode because this information can be easily found on the Internet (I put you anyway some links at the bottom of this article). The purpose of this short article is to explain through a single line of PowerShell commands, how to list all your applications and debug associated mode:<\/p>\n<div id=\"scid:9D7513F9-C04C-4721-824A-2B34F0212519:0035f74b-1605-404c-9b97-e76c01927604\" class=\"wlWriterEditableSmartContent\" style=\"float: none; margin: 0px; padding: 0px;\">\n<pre class=\"brush: powershell; collapse: true; light: false; title: ; toolbar: true; notranslate\" title=\"\"> \r\n# This line is only Required for PowerShell 2.0 \r\nImport-Module WebAdministration \r\nGet-WebConfiguration system.web\/compilation -Recurse | Select @{Name=&quot;ComputerName&quot;;Expression={$env:computername}}, @{Name=&quot;SiteName&quot;;Expression={$_.PSPath.replace(&quot;MACHINE\/WEBROOT\/APPHOST&quot;, &quot;&quot;).TrimStart(&quot;\/&quot;)}}, Debug \r\n<\/pre>\n<\/div>\n<p>Suppose two websites are hosted by us on W2K12R2_IIS001 server: www.contoso.com and www.northwindtraders.com:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"149\" class=\" size-medium wp-image-164 aligncenter\" src=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/03\/IIS-300x149.jpg\" alt=\"IIS\" srcset=\"https:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/03\/IIS-300x149.jpg 300w, https:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/03\/IIS.jpg 367w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>This commands returns the following result :<\/p>\n<p><img decoding=\"async\" class=\" aligncenter\" src=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/03\/debug.jpg\" alt=\"debug\" \/><br \/>\nThe site www.contoso.com is actually in debug mode (which is not a good practice in a production environment). But what is the status for the site www.northwindtraders.com? In fact this site is not listed here because it inherits from the default configuration. If you see output similar to this:<\/p>\n<p><a href=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/03\/debug2.jpg\"><img decoding=\"async\" class=\" aligncenter\" src=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2016\/03\/debug2.jpg\" alt=\"debug2\" \/><\/a><\/p>\n<p>It means that the <b>&lt;compilation debug=\u201cfalse\u201d \/&gt; <\/b><b><\/b>has explicitly been set in the configuration file (the web.config at the root of the site by default).<\/p>\n<p>If you want to deactivate all applications in debug mode at once, you can do it via a simple PowerShell command line (Be careful with the recycling that this will cause however):<\/p>\n<pre class=\"brush: powershell; collapse: true; light: false; title: ; toolbar: true; notranslate\" title=\"\"> \r\n# This line is only Required for PowerShell 2.0 \r\nImport-Module WebAdministration \r\nGet-WebConfiguration system.web\/compilation -Recurse | Where-Object -FilterScript {$_.Debug} | ForEach-Object -Process { Set-WebConfigurationProperty -pspath $_.PSPath -filter &quot;system.web\/compilation&quot; -name &quot;debug&quot; -value &quot;False&quot; -Verbose }\r\n<\/pre>\n<p>Some useful links related to the debug mode (and how to disable it ):<\/p>\n<ul>\n<li>deployment retail=\u201ctrue\u201d pour ASP.NET : <a href=\"https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/sbovo\/deployment-retailtrue-pour-asp-net\">https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/sbovo\/deployment-retailtrue-pour-asp-net<\/a><\/li>\n<li>ASP.NET Memory: If your application is in production\u2026 then why is debug=true : https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/tess\/asp-net-memory-if-your-application-is-in-production-then-why-is-debugtrue<\/li>\n<li>HOW TO: Disable Debugging for ASP.NET Applications : <a href=\"http:\/\/support.microsoft.com\/kb\/815157\/en-us\">http:\/\/support.microsoft.com\/kb\/815157\/en-us <\/a><\/li>\n<li>Why I am not able Turn Off CustomErrors? <a href=\"https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/webtopics\/why-i-am-not-able-turn-off-customerrors\">https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/webtopics\/why-i-am-not-able-turn-off-customerrors<\/a><\/li>\n<li>DeploymentSection.Retail Property : <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.web.configuration.deploymentsection.retail.aspx\">https:\/\/msdn.microsoft.com\/en-us\/library\/system.web.configuration.deploymentsection.retail.aspx <\/a><\/li>\n<\/ul>\n<p>Laurent.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>English version [MAJ : 27\/06\/2019] Ajout du code PowerShell pour d\u00e9sactiver le mode debug sur toutes les applications D&rsquo;exp\u00e9rience je peux assurer que la moiti\u00e9 [&#8230;]<\/p>\n","protected":false},"author":2,"featured_media":2475,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,4,7,19],"tags":[20,25,39],"class_list":["post-144","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net","category-developpement","category-iis","category-powershell","tag-net","tag-iis","tag-powershell"],"_links":{"self":[{"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/posts\/144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/comments?post=144"}],"version-history":[{"count":19,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"predecessor-version":[{"id":2921,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/posts\/144\/revisions\/2921"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/media\/2475"}],"wp:attachment":[{"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}