Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable HTTP Keep-Alive in ASP.NET MVC?

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?

like image 858
Benjamin Pollack Avatar asked Dec 29 '09 18:12

Benjamin Pollack


3 Answers

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.

like image 50
ClearCloud8 Avatar answered Nov 16 '22 01:11

ClearCloud8


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.

like image 32
dnord Avatar answered Nov 16 '22 01:11

dnord


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...

like image 45
user423430 Avatar answered Nov 16 '22 00:11

user423430