user2486993
user2486993

Reputation: 123

Web API 2 and IIS 10 - Sporadic ERR_CONNECTION_RESET

I have an external hosted website and a ASP.NET(Framework 4.5.2) Web API 2 hosted on my local network. The external website makes GET requests on a button click to the API, which queries a MSSQL database and returns JSON to display data on the page. The web API is currently hosted on a windows 10 box running IIS 10.

I’ve installed the Miscrosoft.AspNet.Cors package via the NuGet console and enabled CORS by adding this snippet of code to the Web.config file:

<add name="Access-Control-Allow-Origin" value="*" />

As well as this snippet to WebApiConfig.cs:

config.EnableCors();    

The website works flawlessly when I’m on the same network that the web API is hosted on. I run into issues when on external networks. Occasionally, I receive ERR_CONN_RESET(Chrome) and “The Network Connection was lost” (Safari). The error seems to happen more frequently when I open a fresh browser and navigate to the site. After a few button clicks, the error stops and the page functions normally. I experience similar behavior if I navigate directly to the web api endpoint. The errors are sporadic which has made this problem extremely difficult to troubleshoot. FailedRequest tracing does not create a log since the request isn’t making it to the server. In IIS, I’ve tried changing the Start Mode of the application pool to “Always Running” and also enabled 32 bit applications without any luck. Any ideas on what could cause this problem? At what point can I rule out my code, CORS configuration and IIS configuration? I’m leaning toward this being a network issue but our network admin is convinced the problem is on my end. Any help would be greatly appreciated. This problem has eaten up my entire week and I’m about to pull my hair out!

Upvotes: 2

Views: 2536

Answers (2)

user2486993
user2486993

Reputation: 123

In the end, this ended up being a firewall issue. I ended up replacing the dated sonicwall 2400 and the problems went away. It was very difficult to track down because the firewall was "silently" dropping packets without any logging. As suggested I ran a trace on the firewall, database and application server to determine packets were being dropped.

I suspect the problem caused by stateful firewall settings because sonicwall is known to drop problem packets without any log.

Thanks for the help. Hopefully this post will help someone else someday.

Upvotes: 3

Ravi A.
Ravi A.

Reputation: 2213

You can definitely rule out your code, CORS configuration and IIS configuration. Based on the error code it seems your server is not responding intermittently or could be intermediate device/proxy/firewall blocking the request and hence timing out.

Since your network admin ruled out issue due to intermediate devices you can try couple of things on the machine that has hosted webAPI (none of these going to make you happy)

1) Check http.sys logs (C:\Windows\System32\LogFiles\HTTPERR) and based on the description check here https://support.microsoft.com/en-in/kb/820729

2) Try disabling firewall completely. Go to command prompt (admin mode) and run

NetSh Advfirewall set allprofiles state off

3) If step 2 doesn't help, go to run -> msconfig -> Services -> Hide all Microsoft Services -> Disable All -> Reboot and try.

If nothing works take simultaneous network traces from server and client and your network admin can figure out whats going on.

Upvotes: 2

Related Questions