The Infamous Debug=True Attribute in ASP.NET
page 6 of 9
by Rahul Soni
Feedback
Average Rating: 
Views (Total / Last 10 Days): 99348/ 102

Problem #5

Scripts and images downloaded from the WebResources.axd handler (in ASP.NET 2.0 only) are not cached by the browser when debug=true.

We have seen quite a few issues lately where the customers complain that the pages are running too slowly. They look at Fiddler traces/Netmon and figure out that WebResources.axd is the culprit and is getting called multiple times, thus reducing the performance of the webpage.  The explanation to this behavior is pretty simple. While developing, you keep debug=true and there are chances that you will be modifying the scripts, validators, treeview images and other client resources handled by webresources.axd. You would really not appreciate it if the script and images downloaded from webresources.axd get cached in the browser’s memory because you will have to clear the browser cache every time to check your application. Thus, what is a perfectly reasonable thing to do in development scenario could turn out to be a very big bottleneck on production websites.

When you set debug=false, the cache duration for the items handled by webresource.axd is set to such a value that it is cached at the client (and intermediate proxy servers) as well. Look at the details below. I have modified one.aspx page of this project (see Listing 1) and it contains the following in the page’s <form> tag.

Listing 5

<div>
  <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  <asp:RangeValidator ID="RangeValidator1" runat="server"
   ErrorMessage="RangeValidator" ControlToValidate="TextBox1" MaximumValue="100"
   MinimumValue="10"></asp:RangeValidator>
  <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
 </div>

I am using a simple RangeValidator which is checking a Textbox for values between 10 and 100. This is done to ensure that webresource.axd comes into play. Another thing which you need to do is install Fiddler. This is a free HTTP Debugger tool and I have used this tool to copy the headers of the requests and responses as you can see below.

Let us have a look at the header when debug=true.

Listing 6

GET /DebugTrue/WebResource.axd?d=QmP4A6B4y3bRHKeLCMYC2A2&t=633176900891406250 
HTTP/1.1
 Accept: */*
 Referer: <a href="http://rahulsoni/debugtrue/one.aspx">http://rahulsoni/debugtrue/one.aspx</a>
 Accept-Language: en-us
 UA-CPU: x86
 Accept-Encoding: gzip, deflate
 User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
 Proxy-Connection: Keep-Alive
 Host: rahulsoni
 Cookie: ASP.NET_SessionId=nytwqw450gtuax55sqzmz3mh
HTTP/1.1 200 OK
 Server: Microsoft-IIS/5.1
 Date: Sun, 24 Jun 2007 16:12:25 GMT
 X-Powered-By: ASP.NET
 X-AspNet-Version: 2.0.50727
 Cache-Control: private                             
 Content-Type: application/x-javascript
 Content-Length: 20931

Now, look at the header when debug=false.

Listing 7

GET /DebugTrue/WebResource.axd?d=QmP4A6B4y3bRHKeLCMYC2A2&t=633176900891406250 
HTTP/1.1
 Accept: */*
 Referer: <a href="http://rahulsoni/debugtrue/one.aspx">http://rahulsoni/debugtrue/one.aspx</a>
 Accept-Language: en-us
 UA-CPU: x86
 Accept-Encoding: gzip, deflate
 User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
 Proxy-Connection: Keep-Alive
 Host: rahulsoni
 Cookie: ASP.NET_SessionId=nytwqw450gtuax55sqzmz3mh
HTTP/1.1 200 OK
 Server: Microsoft-IIS/5.1
 Date: Sun, 24 Jun 2007 16:13:31 GMT
 X-Powered-By: ASP.NET
 X-AspNet-Version: 2.0.50727
 Cache-Control: public
 Expires: Mon, 23 Jun 2008 16:13:31 GMT
 Content-Type: application/x-javascript
 Content-Length: 20931

Notice how Expires header is set to an year ahead and how Cache-Control header is changed to Public when you have debug=false.

Figure 10 – Fiddler snapshot with debug=<true/false> showing WebResource.axd

Have a look at the image above and see how webresource.axd is getting called multiple times when debug=true (RED Box). The request number 55 and 62 are two different requests from the same browser session and you will see 57, 58, 64, and 65 making calls to webresource.axd with cache type as private (7th Column).

I changed the debug=false (output after that is in GREEN box above). Notice how the call to webresource.axd is made in 70 and 72 with cache type as public and the expiring date is set to a year ahead! The subsequent click on the button or new requests to one.aspx does not lead to webresoure.axd requests any more. This is a real big performance gain since we are not talking about just the get requests but each and every postback of the pages which deals with webresouce.axd.


View Entire Article

User Comments

Title: NIKE NFL jerseys   
Name: NIKE NFL jerseys
Date: 2012-07-02 10:11:27 AM
Comment:
http://www.jersey2shop.com
http://www.cheapjersey2store.com
http://www.jerseycaptain.com
http://www.yourjerseyhome.com
We are professional jerseys manufacturer from china,wholesal.cheap nike nfl jerseys, mlb jerseys, nhl jerseys,nba jerseys and shoes
Cheap NFL,NBA,MLB,NHL
,heap jerseys,2012 nike nfl Jerseys,nba jersey and shorts,oklahoma city thunder jersey,official jeremy lin new york knicks jersey,NFL Jerseys Wholesale,blake griffin jersey blue,NFL jerseys For Sale online.All Our Jerseys Are Sewn On and Directly From Chinese Jerseys Factory
,Wholesale cheap jerseys,Cheap mlb jerseys,]Nike NFL Jerseys,Cheap China Wholesae,Wholesale jerseys From China,2012 nike nfl Jerseys,Jerseys From China,,2012 nike nfl Jerseys,Revolution 30 nba jerseys,jersey of nba chicago bulls direk rose ,nfl jerseys,green bay packers jerseys wholesale,Buffalo Bills nike nfl jerseys sale,good supplier soccer jerseys,cool base mlb jerseys,Revolution 30 nba jerseys,2012 stanley cup nhl jersey,
We are professional jerseys manufacturer from china,wholesal.cheap nike nfl jerseys, mlb jerseys, nhl jerseys,nba jerseys and shoes. www.yourjerseyhome.com
Title: SS   
Name: SS
Date: 2010-10-03 7:34:45 AM
Comment:
Really a commedable effort for compiling all this in one article..
Title: The Honorable Lord   
Name: Confused
Date: 2009-12-22 2:27:19 PM
Comment:
Sorry, the latest version of my post is the one to keep the older one can be discarded.
Title: The Honorable Lord   
Name: Confused
Date: 2009-12-22 2:08:55 PM
Comment:
.
WINDOWS 7, VS 2008, IIS 7.5
Beautiful write-up. Saved me the time to do it myself.

But, confused: I still do not understand the realtionship betweent he web.config debug= switch and the Configuration Manager setting to Release/Debug ?

I keep 2 separate web.config files one for the HOST one for the dev machine.

My web.config on the HOST is set to debug=false.
I never have had need to compile on the HOST(I wonder if some scenarios require that! ...besides having to DEBUG on HOST for some reason.)
_______________________________________________________
My web.config on the development machine is set to debug=true.
If I set it to false... and attempt to DEBUG... I get prompted to allow the IDE to change it to true for me...
I let it make the change and all is good, I am now allowed to debug.
ok, so far so good.

What I am confused about is the setting in the Configuration Manager(under BUILD option in VS). It is set to Release.
In my old WIN XP Pro dev env, I had to set that to DEBUG to be able to debug. In this new version, I leave it as Release.

So, when I compile(on dev machine)[dll version I will put on the HOST] I find myself making sure the debug= in the web.config is set to false.

Since the Configuration Manager setting is Release... should I not be able to simply leave the debug=true in the web.config on dev machine? Thus satisfying the benefit of avoiding to have to constantly change the setting?

Thus by implication it would mean the debug= switch in the web.config affects JIT only?

2 Notes:
- no matter how I set debug in either or both web.config or configuration manager, I get a pdb file.
- The Configuration Manager option under BUILD will not show until you visit the options and turn it on, on the latest version of VS <- what I nightmare that was to figure out.
.
Title: Pretty good   
Name: Anand
Date: 2009-11-25 11:58:15 PM
Comment:
Pretty good and detailed. We are working on perf issues on a project. This helps a lot. Thanks.
Title: Web Developer   
Name: Raghav Khunger
Date: 2009-04-11 12:51:42 PM
Comment:
Superb Article !!!!!!!!Great Explanation Rahul.
Title: For Gurpiar Singh   
Name: Rahul Soni
Date: 2008-08-01 6:24:59 PM
Comment:
Your assumption is correct Gurpriar. This article mainly talks about the JIT.

There is a pretty neat feature in .NET 2.0 which talk about deployment retail="true" which is supposed to be set in Machine.Config file and that would ensure the .NET Runtime will assume as if debug="false" in all the web.config.

http://msdn.microsoft.com/en-us/library/ms228298.aspx

Hope that helps,
Rahul
Title: Software Architect   
Name: Gurpiar Singh
Date: 2008-08-01 6:05:52 PM
Comment:
We do have debug = false set in web.config on production servers
But we have debug=true set in web.config on Build Machine, where code gets compiled for deployment

And we compile code using MSBuild, with Configuration set to release mode.

The way our Continuous Integration is set up, there is no easy way for us to set this flag to false when code is getting compiled.

So, I am assuming your post applies only while the code is getting deployed and running in production, and not when code actually gets compiled.
Title: Webserver Optimization   
Name: Venkatesh R
Date: 2008-05-12 4:00:33 AM
Comment:
Thanks a ton for the Clear explanation. This Issue causing not only the application but the server resource utilization.
Title: For Milan   
Name: R S
Date: 2007-08-22 11:11:48 AM
Comment:
Hi Milan,

Thanks for your comments.

Precompiled websites are a way to deploy. Notice that you deploy the application under a folder, but not in the Temporary ASP.NET folder. So, although the website is already compiled, it is NOT JIT compiled.

To know more about JIT, you can visit...
http://msdn.microsoft.com/msdnmag/issues/05/05/JITCompiler/default.aspx
Title: how about precompiled site   
Name: mILAN
Date: 2007-08-22 4:03:12 AM
Comment:
How about precompiled websites (in .NET 2)? Since the website is already compiled, I don't think the case is same? Am I correct?
Title: For Craig   
Name: R S
Date: 2007-08-21 7:12:10 PM
Comment:
Hi Craig,

Thanks for your comments. I just wanted to confirm whether you are getting errors when Debug=True? If you are setting it to true, why?

Also, what is the complete error message you get. Do you see anything in the EventLogs?
Title: Why do I have issues when I do Debug=True   
Name: Craig
Date: 2007-08-21 7:08:40 PM
Comment:
Thanks for the article. I modified all the web.configs on my server and everything really starts blowing up. Mostly COM+ errors that reset W3WP.exe. Obviously, this is very bad for our customers. Why would this work fine when debug=false? Is there some underlying problem in our code that is being exposed?
Title: The Infamous Debug=True Attribute in ASP.NET   
Name: .rip
Date: 2007-08-18 5:01:36 AM
Comment:
Great article!!!
Title: The Infamous Debug=True Attribute in ASP.NET   
Name: Sojesh
Date: 2007-08-15 2:02:47 PM
Comment:
Amazing stuff Rahul! Thanks for such a nice article showcasing every possible piece of information about the topic.... as usual!
Title: The Infamous Debug=True Attribute in ASP.NET   
Name: Dan
Date: 2007-08-02 6:19:00 AM
Comment:
This article is absolutely fantastic, MANY thanks :)
Title: The Infamous Debug=True Attribute in ASP.NET   
Name: Saurabh
Date: 2007-08-01 11:11:39 AM
Comment:
This is unarguably the best article i have read on "Debug=true" issue. The depth to which Rahul has gone to explain the repercussions of having debug set to true shoes his expertise and command over the subject.
Excellent job done! A must read for any Asp.Net enthusiast.

Saurabh

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-18 8:31:53 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search