我试图在 ASP dotnet 中运行我的第一个 Web API。问题是当我运行程序时 并打开:http://localhost:5074 浏览器显示:
找不到此本地主机页面
我尝试提供证书,但也没有成功。
我注意到它缺少 https: 端口,我该如何解决这个问题?
请我需要你的经验😢
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5074
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\Users\Seth\DotNetPractice\ContosoPizza
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
Failed to determine the https port for redirect.
我需要配置我的 launchSettings.json 吗?
launchSettings 有哪些不足?
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:32954",
"sslPort": 443
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5074",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7297;http://localhost:5074",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
当您选择如下所示的
http
时,这是预期的行为。
如果选择
https
选项,则它将与 https 一起使用。
请按照我的步骤检查问题。
尝试在浏览器中打开网址
http://localhost:5074/swagger
,检查是否可以看到swagger页面。
检查
Program.cs
文件中的 swagger 设置。
app.UseSwagger();
app.UseSwaggerUI();
如果更改 RoutePrefix ,起始页的 url 将更改。
检查环境变量,可以在这里设置断点。