Welcome to MSDN Blogs Sign in | Join | Help

These tips are reasonably well-known and have been blogged by others.  However, considering how often I come across these common “mistakes”, I felt yet another blog post was worthwhile:


1) Disable ASP.NET debugging in production!
 
I cannot emphasize this enough, Set debug=”false” in all your web.config’s.   I’m regularly pleasantly surprised by how many production issues can be resolved by simply disabling ASP.NET debugging.

 

815157  HOW TO: Disable Debugging for ASP.NET Applications
http://support.microsoft.com/kb/815157

More info on the “evils” of having ASP.NET debugging enabled in production environments is discussed in the following blog post by one of my colleagues:
http://blogs.msdn.com/tess/archive/2006/04/13/asp-net-memory-if-your-application-is-in-production-then-why-is-debug-true.aspx
 

2) Store session state out of process

 

ASP.NET applications can encounter OutOfMemoryException’s (OOM’s) and other undesirable symptoms when .NET is struggling to allocate virtual memory.  Busy sites that store session state in process are likely to encounter OOM’s, particularly if their recycling settings aren’t aggressive enough.  Too aggressive recycling settings can cause problems also.  Storing session state out of process is one of the simplest things you can do to avoid OOM’s and other issues associated with depletion of available virtual memory.  Unfortunately, our default session state store is in process so many don’t consider moving session state out of process until they have a production issue.  Storing session state out of process does have some implications (ie Serializable objects) so it’s worthwhile making this change early in your development cycle so you avoid the inconvenience of having to implement this change under the pressure associated with a production outage.

307598 INFO: ASP.NET State Management Overview
http://support.microsoft.com/kb/307598

 

 

3) Windows Server 2003 (or later)

 

Windows Server 2003 has a number of advantages over Windows 2000 for hosting ASP.NET applications:
a) You can isolate each web application/app domain to its own IIS6 app pool/worker process so they aren’t sharing the same per-process 2Gb virtual address space limitation.
b) You can leverage the various worker process recycling options available in 2003.  Appropriate pre-emptive recycling is a great way to avoid production outages.
c) x64 version allows 4Gb of virtual address space even in 32-bit mode.  Obviously, running out of virtual address space is much less likely if you have the luxury of running in 64-bit mode.
d) /3gb switch works even in the standard version.

 

 

4) .NET 2.0 (or later)

 

.NET 2.0 incorporates a significant number of improvements over .NET 1.x and most .NET 1.x sites will run under .NET 2.0 without modification.  Note, .NET 2.0 isn’t installed by default on Windows Server 2003 so you’ll need to install it manually.  If nothing else, the highly recommended threading configuration settings documented in KB 821268 are defaults in .NET 2.0.

 

821268 Contention, poor performance, and deadlocks when you make Web service requests from ASP.NET applications
http://support.microsoft.com/kb/821268

 

 

5) Increase the allowed number of outbound HTTP connections from the default (2).

 

By default, in order to be a compliant HTTP 1.1 client, .NET only allows 2 outbound HTTP requests per process/host.  Whilst this might be appropriate if you’re building a Winforms app, it can be a bottleneck for server-side applications like ASP.NET websites that are doing web service calls, etc.  You can increase the allowed number of outbound HTTP connections via the maxconnection .config setting.  KB 821268 recommends 12 * N where N is the number of logical CPU’s in your ASP.NET server.

I've been working with a few customers lately that have been experiencing this WebException that has been confirmed as an issue introduced by connection management design changes incorporated into .NET 2.0.  The exception typically ocurrs during a web service call however any scenario involving a HttpWebRequest with keep-alives could encounter this issue. 

 

Note, this issue doesn't occur in .NET 1.x so if you are experiencing this exception in any .NET version prior to .NET 2.0 RTM then I suggest that you are probably dealing with a different issue so KB 915599 is probably a good place to start.

 

The issue involves how we handle the scenario whereby a server has sent a FIN to a keep-alive connection.  We should close the connection and issue the next client request on a new connection. However, in .NET 2.0 RTM, we attempt to reuse the original connection resulting in the server resetting the connection on the next request.  This reset results in this exception being raised in the client.

 

The issue is currently scheduled to be resolved in .NET 3.5.  However, we are also considering the possibility of a hotfix for .NET 2.0.

 

If you suspect that you're hitting this issue, you’ll need to capture Netmon trace(s), ideally from both ends of the network conversation, whilst reproducing the issue.  Generally speaking, it’s preferable to capture network traces from both ends of a conversation as this will allow you to determine if there is any possibility that intermediaries (ie proxy servers, networking hardware) are influencing the conversation.

 

If you’d like to minimise the size of the trace file, you can use a capture filter.

 

Resolutions D, E & F from KB 915599 are potential workarounds for you to consider.  However, resolution D (ie disabling keep-alives) won’t be an option for you if you are using NTLM authentication as it requires keep-alives.

 

*** UPDATE *** The hotfix for .NET 2.0 is available via contacting Microsoft Customer Support Services and quoting KB 941633. http://support.microsoft.com/kb/941633

This is a handy tip to reduce the file size of your Netmon traces.  This is particularlly useful when you need to leave the trace running for an extended period of time.   Thanks go to my collegue Andreja Rusjakovski for this tip...

Just before starting the trace go to Capture->Filter->Load button and select a *.cf file.  An example of the contents of the .cf file for a Port 80 only trace is as follows.  Note, to capture a different port substitue the "0050" for a different value (ie "0050" is hexadecimal for decimal 80).

[CAPTURE FILTER]
VERSION=2
[SAPS ETYPES]
SAPS=1
ETYPES=1
[ADDRESSES]
NLINES=0
[ANDEXP1]
PATTERN1=0, 22, 2,0050
PATTERN2=0, 24, 2,0050

1) Download and install Netmon from the following URL.  Note, the password for the .zip is "trace".

ftp://ftp.microsoft.com/pss/tools/netmon/netmon2.zip


2) Start Netmon.

Administrative Tools->Network Analysis Tools->Network Monitor


3) Select the appropriate network interface.

The first time you run Netmon, you'll be asked to select the network interface to trace.  The following command from the command line should help you to identify the approriate interface via the "Physical Address":

ipconfig /all


4) Increase the buffer settings.

By default, Netmon will only trace up to 1Mb of data before it starts to overwrite the capture buffer.  Set the buffer to a larger size (say 10Mb) via Capture->Buffer Settings menu item.


5) Start the trace via Capture->Start menu item.


6) Reproduce the issue.


7) Stop the trace via the Capture->Stop menu item.


8) Save the trace via the File->Save As menu item.


9) To complement the trace, capture network configuration information to a .txt file:
ipconfig /all > %computername%-ipconfig.txt


10) .ZIP up the .cap and .txt files and send to your Microsoft support representative for analysis.

 
Page view tracker