4

A system I work on is made of multiple .NET Framework APIs, to avoid having to run multiple instances of Visual Studio when working on the system we have set up the APIs to run locally in IIS rather than IIS Express.

I am now trying to do the same for a new .NET Core 2.2 Web API but I am having some trouble with the web.config file Visual Studio autogenerates whenever I launch the application.

This is a fresh .NET Core 2.2 Web API generated with VS 2019. After changing the project to run in IIS instead of IIS Express launchSettings.json looks like

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iis": {
      "applicationUrl": "http://localhost/ExampleApi",
      "sslPort": 0
    },
    "iisExpress": {
      "applicationUrl": "http://localhost:52245",
      "sslPort": 44376
    }
  },
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "IIS Express": {
      "commandName": "IIS",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "ExampleApi": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    }
  }
}

The web.config file Visual Studio generates looks like

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="C:\Program Files\dotnet\dotnet.exe" arguments="exec &quot;C:\Users\Richard\Dev\ExampleApi\ExampleApi\bin\Debug\netcoreapp2.2\ExampleApi.dll&quot;" stdoutLogEnabled="false" hostingModel="InProcess">
        <environmentVariables>
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
        </environmentVariables>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

Note the hardcoded, machine specific paths in aspNetCore. If I delete the paths/elements as soon as I launch the API again the paths are added again.

This means that web.config would need to be gitignored otherwise each developer that runs the API is going to change this file. However, gitignoring the file means that we'd be unable to use a web.config file for IIS settings if we needed to.

Is there a way to avoid this? If not, is there anything major that you can do in web.config that cannot be done in .NET Core middleware or code configuration?

When I've looked up how to do things like set maximum request timeouts or rewrite rules the answers I find seem to be mixed between code and web.config e.g. example 1, link 2

3
  • Add your own web.config in the project. Commented Jun 27, 2019 at 20:36
  • @LexLi that doesn't seem like a very scale-able solution, surely there's a better way. Commented Jun 27, 2019 at 21:33
  • take a look at what docker can do for you when you want to run multiple apps on dev machine Commented Feb 27, 2020 at 14:28

1 Answer 1

1

Project files :

<PropertyGroup>
  <ANCMPreConfiguredForIIS>true</ANCMPreConfiguredForIIS>
</PropertyGroup>

Web.config ;

<aspNetCore processPath="dotnet" arguments="exec &quot;.\bin\Debug\netcoreapp2.2\YOUR_PROJECT.dll&quot;" stdoutLogEnabled="true" stdoutLogFile="..\logs\" hostingModel="inprocess">
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, worked for me. Some details in the answer would be more helpful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.