【发布时间】:2019-07-28 10:08:55
【问题描述】:
我创建了 ASP.NET Core React Web Applicaton(VS 2017,Core 2.2,模板“React.js and Redux”)
只有代码修改是这样的:
public class Program
{
...
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
#if !DEBUG
.UseStartup<Startup>()
.UseUrls("http://*:80");
#else
.UseStartup<Startup>();
#endif
}
然后,我使用以下参数发布它:
- 发布方法“文件系统”;
- 配置:发布;
- 部署模式:自包含;
- 目标运行时:linux-x64
之后,我将“publish”文件夹中的文件复制到 Debian 服务器(Debian GNU/Linux 8.10 (jessie))
然后我开始了:
root@server:~# dotnet "/var/aspnetcore/publish/WebApplicationReactRedux.dll"
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Hosting environment: Production
Content root path: /root
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
到目前为止,一切都还可以。但是当我尝试打开网站时,出现以下错误:
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
An unhandled exception has occurred while executing the request.
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.
at Microsoft.AspNetCore.SpaServices.SpaDefaultPageMiddleware.<>c__DisplayClass0_0.<Attach>b__1(HttpContext context, Func`1 next)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'Page: /Error'
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[3]
Route matched with {page = "/Error", action = "", controller = ""}. Executing page /Error
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[101]
Executing handler method WebApplicationReactRedux.Pages.ErrorModel.OnGet - ModelState is Valid
我尝试用常规的 .NET Core MVC Web 应用程序做同样的事情,没有任何问题。
【问题讨论】:
标签: c# reactjs visual-studio asp.net-core debian