Windows 10 Visual Studio 2019 IIS Express 无法启动并出现错误 500

Windows 10 Visual Studio 2019 IIS Express won't start with error 500

我们在 .Net Core 3.1 中有一个 API 项目。 它在团队中的所有计算机上都能正常工作,但是当尝试在新成员计算机上调试它时却失败了。 它指出存在服务器错误 (500),并且不会启动该程序。 它作为本地服务工作,没有 IIS。

我们已经尝试格式化电脑并重新开始,但没有用。 我看到了与项目配置和启动设置相关的帖子,但由于它在其他机器上工作,我认为这不是问题所在。 我们还尝试在 iis 模板文件和 dll 中添加 aspnetcore 模块所需的行,如在推荐的其他地方看到的那样,得到同样的问题。

如有任何建议,我们将不胜感激!


来自您的 HttpFailure_08-24-17.tml 文件的错误文本

注意:您确实应该将 copied/pasted 作为文本,而不是附加屏幕截图:

The description for Event ID 1034 from source IIS Express AspNetCore Module V2 cannot found.  
Either the component that raises this event is not installed on your local computer or the installation is corrupted. 
You can install or repair the component on the local computer.
... 
The following information was included with the event:

Could not load configuration. Exception message: Unable to get required configuration section 'system.webServer/aspNetCore'.  Possible reason is web.config authoring error.

The request is not supported.

编辑: Program.cs:

 public class Program
{
    public static void Main(string[] args)
    {
        try
        {
            Console.Error.WriteLine("Starting application (from error log without errors)");

            var config = new ConfigurationBuilder().AddEnvironmentVariables("ASPNETCORE_").Build();

            Console.WriteLine("Config set");

            var hostBuilder = new WebHostBuilder()
                .UseKestrel(opt => opt.AddServerHeader = false)
                .UseConfiguration(config)
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>();

            Console.WriteLine("hostBuilder set");

            // ConfigureServices is only used to delay execution until UseIISIntegration()
            // has actually set the "urls" setting.

            Console.WriteLine("urls for hostBuilder " + hostBuilder.GetSetting("urls"));

            hostBuilder.ConfigureServices(services =>
            {
                var urls = hostBuilder.GetSetting("urls");
                urls = string.IsNullOrWhiteSpace(urls) ? "127.0.0.1" : urls.Replace("localhost", "127.0.0.1");
                hostBuilder.UseSetting("urls", urls);
            });

            Console.WriteLine("hostBuilder.ConfigureServices set");

            var host = hostBuilder.Build();

            Console.WriteLine("host set");

            host.Run();

        }
        catch (Exception ex)
        {
            Console.Error.WriteLine(ex.Message);
        }
    }
}

该错误警告您 AspNetCore Module V2 已损坏或丢失。

需要在 IIS 中安装一个模块才能与 AspNetCore 项目兼容(特别是与默认的 Kestrel 服务器一起使用)。

您需要按照these instructions安装此模块。据我所知,它不需要任何额外的配置。

编辑:

我偶然发现了这篇文章,其中提到他们也遇到了 IIS Express 的问题。也许它对您有帮助,并按照他们的指南查找您的配置有什么问题?

https://blog.maartenballiauw.be/post/2019/02/26/asp-net-core-iis-express-empty-error-starting-application.html

似乎我们有一个防病毒软件导致 Visual Studio 2019 安装出错,扰乱了 netcoreapp.dll 和其他。 我要关闭此说明,在关闭防病毒软件并继续安装后, the blog post @Sotiris Koukios-Panopoulos 成功了。