【发布时间】:2020-03-13 21:37:12
【问题描述】:
如果我的 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>
我厌倦了手动将其复制到测试 IIS 并且大多数页面只显示错误 500,尽管我可以浏览 web.config。
【问题讨论】:
-
您能否检查事件日志中是否存在 IIS 组或应用程序组中的任何错误?
-
事件日志本身似乎没有错误,但我厌倦了再次打开站点的配置编辑器,它甚至无法加载 - 它显示“数据无效”并显示空白屏幕。它显然不喜欢上面 web.config 的格式 - core 3.0 有什么变化吗?
-
500.19 错误页面应突出显示配置文件中的错误行。它报告了哪条线路?编辑您的问题以包含它。
-
不幸的是,它没有突出任何东西 - 这就是我完全卡住的原因。该框字面上只是说 Config Source: -1: 0: '.
-
听起来 IIS 网络托管捆绑包未正确安装。您是否检查过 aspnetcore 模块是否映射到正确的位置?也许进程监视器可以帮助您找出根本原因。docs.microsoft.com/en-us/sysinternals/downloads/procmon
标签: iis asp.net-core-3.0