Is there a way to tell IIS/ASP.NET not to allow Keep-Alive for certain requests? Or even for an entire website, if that\'s really the only way to go about it?
HTTP Keep-Alives are enabled by default in IIS 6.0, which complies with the HTTP/1.1 specification for HTTP Keep-Alives. IIS holds open an inactive connection for as long as the ConnectionTimeout metabase property specifies (the default value is 120 seconds).
You can disable HTTP Keep Alive by following below link, it is for enabling you would have to do reverse to disable.
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d7e13ea5-4350-497e-ba34-b25c0e9efd68.mspx?mfr=true
For the whole site, using IIS 7....
<configuration>
<system.webServer>
<httpProtocol allowKeepAlive="false" />
</system.webServer>
</configuration>
PS.
I realize this question is only about how to disable the feature. However, I thought it worth mentioning that disabling KeepAlive was a red herring for the issue I was trying to resolve. I had an issue where a jQuery Ajax POST would fail to send body content to the server. Although enabling/disabling KeepAlive did seem to affect how much I could reproduce my issue, the actual fix was disabling Windows Authentication at the site root. This is because of the fact that the browser (behind the scenes) sends a request for favicon.ico at the website's root (even outside of your app folder) and if you have Windows Auth turned on at that level, NTLM Authenticate handshake begins, and (in technical terms) it jacks everything up.
So I ended up removing this line from my config file so that it would operate as the default setting, with KeepAlive enabled..... which by the way is supposed to better for performance.
Pretty sure it can't be done at the request level.
In IIS 6.0, it was exposed in a tab of IIS properties. In IIS 7, they kind of hid it.
If you really want to do this, adapt the IHttpModule in this answer to call Response.Close in the HttpApplication.EndRequest handler.
“don’t use this API ever”
more info on the ways to end a response...