系统相关
首页 > 系统相关> > windows下asp.net core 低成本最简化部署方式

windows下asp.net core 低成本最简化部署方式

作者:互联网

直接使用exe运行

大家都知道, .net core 是跨平台的,可以运行在任何操作系统。新的asp.net core 可以不再依赖IIS部署。
最简化的部署方式,无非就是双击web站点的exe程序运行。

如下图:

默认情况下,会自动启动

info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using 'C:\Users\Administrator\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: D:\Codes\Github\rickxie\Projects\Project.Alpha\Project.Core\bin\Debug\netcoreapp3.1

发布独立运行模式

发布程序配置为独立, 目标通常为x64

绑定不同的域名和端口

框架默认提供4种绑定方式
Specify URLs using the:

Kestrel配置

ppsettings.json文件中会加载使用Kestrel配置, 程序启动时会默认加载此文件。

{
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://localhost:5000"
      },
      "HttpsInlineCertFile": {
        "Url": "https://localhost:5001",
        "Certificate": {
          "Path": "<path to .pfx file>",
          "Password": "<certificate password>"
        }
      },
      "HttpsInlineCertStore": {
        "Url": "https://localhost:5002",
        "Certificate": {
          "Subject": "<subject; required>",
          "Store": "<certificate store; required>",
          "Location": "<location; defaults to CurrentUser>",
          "AllowInvalid": "<true or false; defaults to false>"
        }
      },
      "HttpsDefaultCert": {
        "Url": "https://localhost:5003"
      },
      "Https": {
        "Url": "https://*:5004",
        "Certificate": {
          "Path": "<path to .pfx file>",
          "Password": "<certificate password>"
        }
      }
    },
    "Certificates": {
      "Default": {
        "Path": "<path to .pfx file>",
        "Password": "<certificate password>"
      }
    }
  }
}

最简化配置

在应用程序根目录的appsettings.json文件中,新增以下配置:

若部署在云上,仍无法访问,建议检查是否开启安全策略开放端口。

本机内部开启防火墙配置

确保本地操作系统防火墙允许访问此端口。

netsh advfirewall firewall add rule name="Http Port 80" dir=in action=allow protocol=TCP localport=80

确保管理员模式运行

某些情况下,例如配置了https证数等,需要管理员权限。最好是以管理员模式运行。

祝你配置成功,成功运行!

参考来源:
[1] https://weblog.west-wind.com/posts/2016/Sep/28/External-Network-Access-to-Kestrel-and-IIS-Express-in-ASPNET-Core#open-your-firewall
[2] https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1#endpoint-configuration

标签:info,core,asp,windows,Hosting,https,Lifetime,Microsoft,localhost
来源: https://www.cnblogs.com/Mikor/p/13054105.html