gpt4 book ai didi

c# - dotnet 构建 - 出现错误 "could not return the default page '/index.html'"

转载 作者:行者123 更新时间:2023-12-01 23:43:29 29 4
gpt4 key购买 nike

尝试将我的项目生成为exe文件,但出现错误:

之前:“dotnet build -r win10-x86”可以

运行生成的exe后,一切正常:

indows DPAPI to encrypt keys at rest.
Hosting environment: Production
Content root path: C:....\currencyColution\correncyProject\bin\Debug\netcoreapp2.1\win10-x86
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.

加载页面后有些磨损,更准确地说找不到index.html:

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://localhost:5000/
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLG91TC2H0UO", Request id "0HLG91TC2H0UO:00000001": An

unhandled exception was thrown by the application.
System.InvalidOperationException: The SPA default page middleware could not return the default page '/index.html' because it was not found, and no other middleware handled the request.
Your application is running in Production mode, so make sure it has been published, or that you have built your SPA manually. Alternatively you may wish to switch to the Development environment.

Startup.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.AngularCli;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.Swagger;
using System;
using System.IO;
using Microsoft.AspNetCore.Http;

namespace AspNetCore2Ang6Template
{
public class Startup
{

public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSpaStaticFiles(c =>
{
c.RootPath = "wwwroot";
});

}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseDefaultFiles();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(name: "default", template: "{controller}/{action=index}/{id}");
});

app.UseSpa(spa =>
{
spa.Options.SourcePath = "wwwroot";
});

}
}
}

我不使用 Angular 和其他一些,只是尝试打开 wwwroot/index.html

files:

currencyProject

wwwroot

Program.cs

Startup.cs

在 VS 中测试,一切正常,但不能通过 exe 构建器

像 dev : dotnet run 一样启动,然后它可以在 localhost:58893/上运行,但是在 localhost:5000 上构建 prod dotnet 有什么问题

启动设置:

{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:58842/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"AspNetCore2Ang6Template": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:58893/"
}
}
}

最佳答案

检查 angular.json 文件使用 "outputPath": "dist",

和启动文件

 services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});

关于c# - dotnet 构建 - 出现错误 "could not return the default page '/index.html'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51989817/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com