首页 > 解决方案 > azure 应用服务中的 Kestrel 地址绑定错误

问题描述

我有一个 aspnet core 2.2 应用程序,它看起来像这样:

return WebHost.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration((builderContext, config) =>
    {
        var env = builderContext.HostingEnvironment;

        config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
    })
    .UseStartup<Startup>()
    .UseKestrel(options =>
    {
        options.ConfigureHttpsDefaults(opts =>
        {
            opts.ServerCertificate = GetCertificate();
            opts.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
            opts.ClientCertificateValidation = CertificateValidator.DisableChannelValidation;
        });
    });

一切都在当地运作良好。但是,当部署到 azure 应用服务时,我得到以下信息:

Unhandled Exception: System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use

有什么特别的我需要在这里做不同的吗?只要我可以执行客户端证书身份验证(在我当前的实现中本地工作),我并不特别关心使用 Kestrel 与其他任何东西。

标签: asp.net-coreazure-web-app-serviceazure-webapps

解决方案


问题原来是应用程序已经在运行,但由于尝试在 azure 应用程序服务中使用 kestrel 而没有接受请求。我不得不用.UseIIS()它来让它工作。也许我做错了什么。


推荐阅读