IIS config error after upgrading to ASP.NET Core 3.0 from Core 2.2

0

I upgraded a few if my web projects to asp.net core 3.0 and am trying to push them to an IIS web server. I installed the .net core 3.0 hosting bundle and runtime and uninstalled the old versions just in case.

I tried to load the page but I get the error:

HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Error Code     0x8007000d
Config Error       
Config File    \\?\C:\inetpub\MySite\web.config

Below is my web.config:

<?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="dotnet" arguments=".\MySite.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="">
        <environmentVariables>
          <environmentVariable name="EXCLUDED_LINE" value="Test" />
          <environmentVariable name="COMPLUS_ForceENC" value="1" />
        </environmentVariables>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

Other than the version of .net I haven't changed anything else on the server - I am directly replacing the pervious working projects.

startup.cs:

using System;
using FluentValidation;
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.IISIntegration;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace MySite
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        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;
            });

            services.AddAuthentication(IISDefaults.AuthenticationScheme);

            services.AddTransient<IClaimsTransformation, CustomClaimsTransformer>();

            services.AddSingleton<IAuthorizationHandler, CheckADGroupHandler>();

            services.AddRazorPages().AddFluentValidation();

            services.AddDbContext<MyContext>(options =>
                options.UseSqlServer(
                    "Data Source=MYSERVER\\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"));
        }

            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints => endpoints.MapRazorPages());

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

        }
    }
}

project:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
    <AssemblyName>MySite</AssemblyName>
    <RootNamespace>MySite</RootNamespace>
    <LangVersion>8</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="BuildBundlerMinifier" Version="2.9.406" />
    <PackageReference Include="FluentValidation.AspNetCore" Version="8.5.0" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
    <PackageReference Include="Microsoft.Windows.Compatibility" Version="3.0.0" />
    <PackageReference Include="NLog" Version="4.6.2" />
    <PackageReference Include="NLog.Targets.Syslog" Version="5.1.0" />
    <PackageReference Include="NLog.Web.AspNetCore" Version="4.8.1" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="wwwroot\css" />
    <Folder Include="wwwroot\webfonts\" />
  </ItemGroup>

</Project>

I tired putting manually copying it to a test IIS and most pages just show error 500, although I can browse the web.config.

iis
asp.net-core-3.0
asked on Stack Overflow Nov 18, 2019 by Hawke • edited Nov 18, 2019 by Hawke

1 Answer

0

I experienced the issue both on a new server and on a server which I uninstalled core 2.2 before installing 3.0. Eventually I found a server that worked and realised I had forgotten to uninstall the old hosting bundle so it had both 2.2 and 3.0

In the end I fixed it by installing the asp.net core 2.2 hosting bundle on the servers alongside asp.net core 3.0 hosting. Site is now working fine.

answered on Stack Overflow Nov 20, 2019 by Hawke

User contributions licensed under CC BY-SA 3.0