IIS服务器上.NET应用HTTPS访问故障排查求助
IIS服务器上.NET应用HTTPS访问故障排查求助
大家好,我碰到个棘手的问题,想请各位大佬帮忙分析下:
我有一台IIS服务器,需要的组件都已经装全了。本地构建运行时HTTPS完全正常,但部署到服务器之后,HTTPS就彻底访问不了了。用端口扫描工具能看到44390端口是开放的,事件管理器也显示进程已经启动,而且HTTP是完全可以正常访问的,唯独HTTPS不行。
更奇怪的是,同一台IIS上还有个Vue3的前端项目,用的是同一个SSL证书,运行完全没问题,偏偏这个.NET应用就出问题…我实在找不到哪里错了,求各位帮忙看看!
Program.cs 代码
using BaseBackend.Controllers; using Microsoft.AspNetCore.Authentication.Cookies; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); // For MVC support builder.Services.AddControllers(); // For API support // Configure Swagger/OpenAPI builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); // Register IConfiguration for DI //builder.Services.AddSingleton<IConfiguration>(builder.Configuration); // Register TuningDatabaseHandler for DI builder.Services.AddScoped<TuningDatabaseHandler>(); builder.Services.AddScoped<MyUploadedFileHandler>(); builder.Services.AddScoped<StringReplacementHandler>(); builder.Services.AddScoped<TaskHandler>(); builder.Services.AddScoped<EcuHandler>(); // Configure Authentication builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/api/login"; options.LogoutPath = "/api/logout"; options.Cookie.HttpOnly = true; }); // Configure Authorization builder.Services.AddAuthorization(); // Configure CORS builder.Services.AddCors(options => { options.AddPolicy("AllowFrontend", builder => { builder.WithOrigins("https://localhost") .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); }); builder.Services.AddHttpsRedirection(options => { options.HttpsPort = 44390; // Specify the HTTPS port where is same in IIS }); var app = builder.Build(); // Configure the HTTP request pipeline. app.UseSwagger(); app.UseSwaggerUI(); // Enable CORS policy app.UseCors("AllowFrontend"); //app.UseHttpsRedirection(); // Use authentication and authorization middleware app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); app.MapGet("/", () => "Test Page: Application is Running!"); app.Run();
appsettings.json 配置
{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*", "Swagger": { "Enabled": true }, "ConnectionStrings": { "dbo": "Server=.\\SQLEXPRESS;Integrated Security=True;Database=dbo;" }, "Kestrel": { "Endpoints": { "Https": { "Url": "https://localhost:44390" // Set HTTPS to listen on port 44390 } } } }
备注:内容来源于stack exchange,提问作者Yusuf Keks
相关产品推荐
相关产品推荐

