一、修改Program.cs代碼,注冊(cè)為 Windows Service
如果不注冊(cè)builder.Host.UseWindowsService(); 安裝為window服務(wù)會(huì)啟動(dòng)報(bào)錯(cuò)
安裝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();
二、發(fā)布項(xiàng)目
1、以文件夾形式
2、目標(biāo)運(yùn)行時(shí)選對(duì)應(yīng)的平臺(tái)(本Coder是:winx-64)
3、文件夾選項(xiàng):在發(fā)布前刪除所有現(xiàn)有文件
三、部署到IIS
1、需要安裝 Hosting Bundle IIS 運(yùn)行時(shí)支持 (ASP.NET Core Module v2)
2、IIS部署項(xiàng)目
官方版本地址:https://dotnet.microsoft.com/download/dotnet
.NET 6.0地址:https://dotnet.microsoft.com/zh-cn/download/dotnet/6.0
四、以windows部署,安裝windows服務(wù)
1、安裝win服務(wù):sc create “windows服務(wù)名稱” binPath=(空格)“發(fā)布的項(xiàng)目路徑.exe“
例如:sc create ”PDD.ManageMent” binPath= “D:\PDD.ManageMent.exe”
2、卸載win服務(wù):sc delete ”PDD.ManageMent"
命令提示符,以管理員身份運(yùn)行
啟動(dòng)win服務(wù)
文章來源:http://www.zghlxwxcb.cn/news/detail-515416.html
五、瀏覽器打開端口,看成就
文章來源地址http://www.zghlxwxcb.cn/news/detail-515416.html
到了這里,關(guān)于.net6 core web項(xiàng)目發(fā)布部署到IIS,以Windows服務(wù)的形式部署啟動(dòng)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!