首页 > 解决方案 > ASP.NET Core:重定向问题

问题描述

我有从 http 重定向到 https 的问题:

http:*** => https:***:44345 是否可以不在 url 中显示端口 44345?

我的项目配置:

启动设置.json:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:57854",
      "sslPort": 44345
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Site": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

启动.cs:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseHsts();
    app.UseFileServer();
    app.UseHttpsRedirection();
    app.UseRouting();
    app.UseAuthentication();
    app.UseAuthorization();
    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllers();
        endpoints.MapRazorPages();
    });
}

请指教

标签: asp.net-core

解决方案


只有 http 和 https 的端口 80 和 443 分别允许在地址中省略端口。这是因为您的浏览器会看到 http 或 https 并透明地向适合该协议的端口发出请求。


推荐阅读