ASP.NET Core 2.2: web.config and deployment to IIS


Big Edits

I have a C# ASP.Net core 2.2 (was 2.1 in original question) web app that I am trying to deploy to an IIS 8.5 server. The deployment happens. I can reach the default route and the server side actions work for that route. None of the other defined routes work though. On the IIS Server, If I try for an MyInitialController action other than Index I get the error page:

    HTTP Error 500.19 - Internal Server Error
    The requested page cannot be accessed because the related configuration data for the page is invalid.

    Detailed Error Information:
    Module     IIS Web Core
    Notification       BeginRequest
    Handler    Not yet determined
    Error Code     0x80070003
    Config Error       Cannot read configuration file
    Config File    \\?\E:\www\\Content\MyInitialController\web.config
    Requested URL
    Physical Path      E:\www\\Content\MyInitialController\Calendar
    Logon Method       Not yet determined
    Logon User     Not yet determined

    Config Source:

    More Information:
    This error occurs when there is a problem reading the configuration file for the Web server or Web application. In some cases, the event logs may contain more information about what caused this error.
    View more information ยป

Note the value of Config File. On the IIS server there is no folder named: "MyInitialController". The "root" of the IIS site folder is: \?\E:\www\\Content. I have no idea what is causing it to think that the web.config should be one level down in a folder that does not exist.


using System;
using CalendarMyInitialControllers.Models.Commodities;
using CalendarMyInitialControllers.Models.UserTracking;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace CalendarMyInitialControllers {
    public class Startup {
        public Startup(IHostingEnvironment env) {
            var builder = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json", true, true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", true)

            Configuration = builder.Build();

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services) {
            services.Configure<CookiePolicyOptions>(options => {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;

            // Add memory cache services

            services.AddSession(options => {
                options.IdleTimeout = TimeSpan.FromMinutes(600); //You can set Time   

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
            if (env.IsDevelopment()) {
            } else {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see


            app.UseMvc(routes => {


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


  "Logging": {
    "LogLevel": {
      "Default": "Warning"
  "AllowedHosts": "*"
asked on Stack Overflow May 15, 2019 by 7 Reeds • edited May 16, 2019 by 7 Reeds

2 Answers


First, be sure to read the Host ASP.NET Core on Windows with IIS. As the guide says in the beginning, make sure you have the hosting bundle installed.

In the guide, it mentions you will need a web.config here.

There is a more detailed guide for web.config here.

When I publish through Visual Studio, one is created for me. If that doesn't happen for you, you can always manually add a web.config at the root of your project. In fact, that's usually a better approach.

A basic example of a web.config would be:

<?xml version="1.0" encoding="utf-8"?>
  <location path="." inheritInChildApplications="false">
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      <aspNetCore processPath=".\MyApp.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
answered on Stack Overflow May 15, 2019 by John-Luke Laue

I found the unexpected MyInitialController dir issue. The IIS Server Admin created the "Base Settings" -> "Base Path" string as\Content\MyInitialController. I removed the trailing MyInitialController and restarted the site. I now have other issues but this one is closed.

answered on Stack Overflow May 17, 2019 by 7 Reeds

User contributions licensed under CC BY-SA 3.0