Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core Web api call ERR_CONNECTION_RESET only on IIS - other calls working

I'm now at a complete loss...

I have a .NET Core web app, and running locally everything is working. There's a number of WebAPI end points, again all working as intended with GET and returning JSON correctly.

When I publish to IIS, one, and only one of these end points stop working and throw (failed) net:ERR_CONNECTION_RESET (in Chrome - other browsers throw their own errors).

What is peculiar is that all the other Web API calls are working, all in the same environment and calling the same database, using the same context and EF data service.

What I can't figure out, is how to get detailed logs from Kestrel into some other logging services, either Windows Event Viewer, a text file, emails or anything else! I've not used much of the logging middleware, with the intention to hook that up as we get closer to production.

What's the best way to try and troubleshoot this in IIS 8 on Windows 2012 R2 with the .NET core Kestrel web server?

like image 203
RemarkLima Avatar asked Jan 05 '17 16:01

RemarkLima


People also ask

What does Net :: Err_connection_reset mean?

If you run into the “ERR_CONNECTION_RESET” error, it means that your browser can't establish a connection to the remote server. In most cases, it's due to a misconfiguration in your internet settings or something else that's blocking the connection.


2 Answers

I had a similar problem. I am using Entity Framework Core 1.1, which does not allow Lazy Loading. My error was caused from an object graph loop in a many-to-many relationship.

As EFCore 1.1 does not support many-to-many out of the box, my models had looping references. My JSON Serializer became stuck in an infinite loop as it attempted to serialize the data returned from my controller class.

If you have this problem and none of the other solutions work, I suggest changing your Startup.cs file ConfigureServices() method. The line services.AddMvc(); should be changed to this:

services.AddMvc()
    .AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
like image 91
birwin Avatar answered Sep 23 '22 14:09

birwin


Just edit your web.config and set stdoutLogEnabled="true"to true, as well as set the path where the logfile will be written to.

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <!--
    Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
  -->

  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>

But you need to enable at least the console logger, as it basically dumbs the console output to a file.

public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
    loggerFactory.AddConsole(Configuration.GetSection("Logging"));
    loggerFactory.AddDebug();
    ...
}

The "Logging" section is configured in appsettings.json, such as

  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
like image 20
Tseng Avatar answered Sep 25 '22 14:09

Tseng