首页IT科技asp.net core5.0(.net6 core web项目发布部署到IIS,以Windows服务的形式部署启动)

asp.net core5.0(.net6 core web项目发布部署到IIS,以Windows服务的形式部署启动)

时间2025-06-21 02:40:58分类IT科技浏览4060
导读:一、修改Program.cs代码,注册为 Windows Service 如果不注册builder.Host.UseWindowsService( ; 安装为window服务会启动报错...

一            、修改Program.cs代码              ,注册为 Windows Service

如果不注册builder.Host.UseWindowsService(); 安装为window服务会启动报错

安装NuGet包

Microsoft.Extensions.Hosting.WindowsServices

Program.cs代码 var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); builder.Host.UseWindowsService(); builder.WebHost.UseUrls("http://*:5010"); 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(); 二                    、发布项目

1      、以文件夹形式

2         、目标运行时选对应的平台(本Coder是:winx-64)

3                    、文件夹选项:在发布前删除所有现有文件 三          、部署到IIS

1      、需要安装 Hosting Bundle

IIS 运行时支持 (ASP.NET Core Module v2)

2                   、IIS部署项目

官方版本地址:https://dotnet.microsoft.com/download/dotnet

.NET 6.0地址:https://dotnet.microsoft.com/zh-cn/download/dotnet/6.0 四              、以windows部署                  ,安装windows服务

1   、安装win服务:sc create “windows服务名称              ” binPath=(空格)

“发布的项目路径.exe“

例如:sc create                   ”PDD.ManageMent      ” binPath= “D:\PDD.ManageMent.exe           ”

2                  、卸载win服务:sc delete                   ”PDD.ManageMent" 命令提示符      ,以管理员身份运行 启动win服务 五                 、浏览器打开端口           ,看成就

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
高质量的seo文章怎么写好(《SEO文章评分:提升网站排名的必备利器》)