Visual Studio 2022无法连接HTTPS服务器,UI页面无法正常显示求助
ASP.NET Core UI项目连接错误排查问题
问题描述
负责的项目包含API和UI两个模块。在UI模块中修改index.cshtml后,按下Ctrl + Shift + W试图查看页面效果,却遇到连接错误,Visual Studio界面和调试控制台均报错,偶尔还会出现其他连接类错误。
尝试过删除并重新添加UI项目Properties/launchSettings.json,问题未解决。查看项目调试属性的HTTP、HTTPS和IIS部分时,曾将IIS的localhost地址复制到HTTPS配置项,虽能运行但打开的是Swagger页面,而非目标UI页面。此外找不到项目属性中启用/禁用SSL的选项。
目前HTTP、HTTPS和IIS三种运行方式均无法正常显示修改后的UI页面,不确定是localhost配置还是证书问题。
已尝试的解决方案
- 执行命令:
dotnet dev-certs https --clean和dotnet dev-certs https --trust - 通过「添加或删除程序」卸载IIS Express,执行
dotnet dev-certs https --clean后重新安装,运行项目时生成证书,但添加到受信任根时提示「Access Denied」 - 通过MMC控制台将「IIS Express Development Certificate」证书从「个人」证书目录剪切粘贴到「受信任的根证书颁发机构」目录
相关项目文件
UI项目(RealEstate_Dapper_UI)
Properties/launchSettings.json
{ "$schema": "http://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:29591", "sslPort": 44379 } }, "profiles": { "http": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "http://localhost:5112", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "https://localhost:7240;http://localhost:5112", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }
Views/Home/Index.cshtml
@{ ViewData["Title"] = "Index"; Layout = "~/Views/Shared/_MemberLayout.cshtml"; } <h1>Index</h1>
Program.cs
var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run();
API项目(RealEstate_Dapper_Api)
Properties/launchSettings.json
{ "$schema": "http://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:21668", "sslPort": 44323 } }, "profiles": { "http": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", "applicationUrl": "http://localhost:5027", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", "applicationUrl": "https://localhost:7032;http://localhost:5027", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }
调试属性截图说明
- HTTPS属性截图:展示项目HTTPS调试配置界面,包含应用URL、环境变量等设置项
- IIS属性截图:展示项目IIS Express调试配置界面,包含应用URL、SSL端口等设置项
- HTTP属性截图:展示项目HTTP调试配置界面,包含应用URL、环境变量等设置项
内容的提问来源于stack exchange,提问作者kagan turkay
相关产品推荐
相关产品推荐

