簡體   English   中英

.net 核心 3.1 Web API 托管為 ZAEA23489CE3AA9B6406EBB28E0CDA 服務未顯示頁面

[英].net core 3.1 Web API hosting as Windows Service not showing pages

我正在嘗試將 windows 服務 3.1 托管為 windows 服務。 但是,我不斷將頁面顯示為“無法訪問此站點”

如果我運行部署在 IIS 中的應用程序,一切正常。

.net 內核也有 angular 8 個客戶端應用程序。

程序.CS

public static void Main(string[] args)
{
    CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
        }).ConfigureWebHost(config =>
        {
            config.UseUrls("http://*:9095/");
        }).UseWindowsService();

啟動.CS

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllersWithViews();
    // In production, the Angular files will be served from this directory
    services.AddSpaStaticFiles(configuration =>
    {
        configuration.RootPath = "ClientApp/dist";
    });
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Error");
    }

    app.UseStaticFiles();
    if (!env.IsDevelopment())
    {
        app.UseSpaStaticFiles();
    }

    app.UseRouting();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller}/{action=Index}/{id?}");
    });

    app.UseSpa(spa =>
    {
        
        spa.Options.SourcePath = "ClientApp";

        if (env.IsDevelopment())
        {
            spa.UseAngularCliServer(npmScript: "start");
        }
    });
}

我能夠發布項目並創建 windows 服務並啟動它。

在此處輸入圖像描述

用於創建服務的命令:

**sc create MyWinService binPath="D:\MyWinService\bin\Release\netcoreapp3.1\win-x64\MyWinService.exe"

[SC] 創建服務成功**

並從 msc.service 啟動服務

之后訪問 URL: http://localhost:9095/沒有結果

在此處輸入圖像描述

您正在安裝錯誤的 EXE 文件

sc create MyWinService binPath="D:\MyWinService\bin\Release\netcoreapp3.1\win-x64\MyWinService.exe

它應該是

sc create MyWinService binPath="D:\MyWinService\bin\Release\netcoreapp3.1\publish\MyWinService.exe

D:\MyWinService\bin\Release\netcoreapp3.1\win-x64 不包含ClientApp文件夾

在防火牆中添加規則以允許使用給定端口訪問此服務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM