1

I have a simple API, when I run the API in Visual Studio 2019 it works perfectly, I'm using swagger to see that it worked. Doesn’t matter if its debug or release and I can use ISS Express or Kestrel. While it's called from the IDE it works.

When I use it outside of Visual Studio IDE it does not work. Is a 404 not found. It seems to not read properly the configuration. I tried many things (command line dotnet MyAPI.dll, publishing it and try it in a server…) but if used outside of VS , it does not work. I’m guessing somehow It does not read the properly the configuration because in all tries (outside of IDE) it ends up using default ports (5000 and 5001).

It is probably something simple. The configuration I believe is lost is the one in launcherSettings.json that you can see here:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:53907/",
      "sslPort": 44369
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "MyAPI": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:44369;http://localhost:5000"
    }
  }
}

Any idea what I'm doing wrong?

Edit...

web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <remove name="aspNetCore"/>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
  <!-- Config de ultima solucion https://stackoverflow.com/questions/4022434/how-to-set-the-maxallowedcontentlength-to-500mb-while-running-on-iis7-->
  <system.web>
    <!-- ~ 2GB -->
    <httpRuntime maxRequestLength="2147483647" />
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- ~ 4GB -->
        <requestLimits maxAllowedContentLength="4294967295" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

To keep things more simple I'm using now Kestel (simply picking the entry point for the current project). Then what debug does is compile and execute the Debug/*.exe, it runs in 44369 as set in the config.

However if I go to that folder and doble click on the exe it works in port 5001. To this https://localhost:5001/swagger/index.html the response is now a 404 Not Found.

Pedro
  • 87
  • 1
  • 10
  • outside of VS , i would assume you run in IIS? 1. check in web.config path to dll. 2. is it runs as website or we application? – Power Mouse May 26 '22 at 17:19
  • Do you also get 404 errors when running in IIS? Did you trace the detailed error message? Can you post the detailed error message? – JennyDai May 27 '22 at 09:14
  • @PowerMouse is a web application ASP.Net Core project. I tryed in a server with IIS publishing etc. It didn't work so now I'm trying local. Also I'm trying with Kestrel too. – Pedro May 27 '22 at 13:07

1 Answers1

1

Well, I'm answering my own question with the findings I've got.

  • First, I found an error in web.config. Commenting <system.webServer> solved the exception when run in IIS.
  • Second, automatic code to use swagger has a condition (IsDevelop). <- Yes, was that simple...
  • Third, the problem why ports do not change according to configuration when I run the API from the folder (or CMD) persist. However, when use IIS you can configure there your ports, so it is not a big deal.
Pedro
  • 87
  • 1
  • 10