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?
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With