托管的.Net Core 3.1 Webapi和ERR_CONNECTION_RESET

时间:2019-12-30 20:19:18

标签: ssl asp.net-core iis

我有一个使用.net core 3.1在VS2019中创建的webapi项目 该项目的目的是测试身份验证和授权。 我能够使用IIS Express运行该项目,所有路由均按预期工作。

但是,当我发布项目并尝试将其托管在本地IIS服务器中时,当尝试访问匿名路由时,会收到ERR_CONNECTION_RESET。

如果我在发布文件夹中运行“ dotnet TestAPI.dll”,则可以将API与https://localhost:5001一起使用 尝试从IIS https://localhost/TestAPI/使用它时,我得到ERR_CONNECTION_RESET。这是使用“默认网站”:80和:443。

Startup.cs


public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();
    SetAuthenticationStrategy(services);
    services.AddScoped<IAuthService, PocAuthService>();
}

private void SetAuthenticationStrategy(IServiceCollection services)
{
    var appSettingsSection = Configuration.GetSection("AppSettings");
    services.Configure<AppSettings>(appSettingsSection);

    var appSettings = appSettingsSection.Get<AppSettings>();
    var key = Encoding.ASCII.GetBytes(appSettings.Secret);

    services.AddAuthentication(x =>
    {
        x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
        x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
    })
    .AddJwtBearer(x =>
    {
        x.RequireHttpsMetadata = false;
        x.SaveToken = true;
        x.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuerSigningKey = false,
            IssuerSigningKey = new SymmetricSecurityKey(key),
            ValidateIssuer = false,
            ValidateAudience = false,
            ClockSkew = TimeSpan.Zero
        };
    });
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseHttpsRedirection();
    app.UseAuthentication();

    app.UseRouting();

    app.UseAuthorization();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllers();
    });
}


我想念什么?

0 个答案:

没有答案