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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
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.
Method 3
If you really want to do this, adapt the IHttpModule in this answer to call Response.Close in the HttpApplication.EndRequest handler.
more info on the ways to end a response…
Method 4
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0