从Core 2.2升级到ASP.NET Core 3.0后,IIS配置错误

时间:2019-11-18 13:38:36

标签: iis asp.net-core-3.0

如果我的Web项目升级到asp.net core 3.0,我已经升级了一些,并试图将它们推送到IIS Web服务器。我安装了.net core 3.0托管包和运行时,并卸载了旧版本,以防万一。

我尝试加载页面,但出现错误:

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

下面是我的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>

除了.net版本以外,我没有在服务器上进行任何其他更改-我将直接替换以前的工作项目。

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 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>

尽管我可以浏览web.config,但我很讨厌手动将其复制到测试IIS,大多数页面仅显示错误500。

1 个答案:

答案 0 :(得分:0)

我在新服务器和在安装3.0之前卸载了core 2.2的服务器上都遇到了该问题。最终,我发现一台可以正常工作的服务器,并意识到我忘记了卸载旧的托管捆绑软件,因此它同时具有2.2和3.0

最后,我通过在服务器上与asp.net core 3.0托管一起安装了asp.net core 2.2托管捆绑包来修复了它。网站现在可以正常工作。