我是Angular2的新手,对于将它合并到ASP.NET Web应用程序中是一个新手。 当我尝试在我的Angular2 ASP.NET Web应用程序中以调试模式构建时,出现此错误。在发布模式下构建时,我遇到了同样的错误。Angular2在ASP.NET中 - 窗口没有定义
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[0] An unhandled exception has occurred while executing the request Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException: Prerendering failed because of error: ReferenceError: window is not defined at D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\vendor.js:89981:21 at Object.<anonymous> (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\vendor.js:90732:3) at Object.<anonymous> (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\vendor.js:90734:30) at __webpack_require__ (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\vendor.js:21:30) at Object.<anonymous> (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\vendor.js:85385:1) at Object.<anonymous> (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\vendor.js:85386:30) at __webpack_require__ (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\vendor.js:21:30) at Object.<anonymous> (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\main-server.js:20466:42) at __webpack_require__ (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\main-server.js:20:30) at Object.exports.REPLACEMENT_CHARACTER (D:\Projects\BryterOpsAdmin\BryterOpsAdmin\ClientApp\dist\main-server.js:398:79) Current directory is: D:\Projects\BryterOpsAdmin\BryterOpsAdmin
我刚刚做了一些微不足道的变化对模型类的MVC的一面,所以,当我得到这个错误我恢复了我的变化,并再次尝试。 我仍然收到此错误。根据我的源代码控制,自上次正常工作以来绝对没有发生任何变化。 什么可能导致此错误?我完全被难住甚至试图寻找什么。
我搜索了StackOverflow的任何相关的东西,但是我没有发现任何适用于asp.net的东西,除了这个问题:Prerendering failed because of error: ReferenceError: window is not defined 这是从未回答。
我试图删除隐藏的obj和bin文件夹无济于事。
预先感谢您。
更新: 我试着直接导航到我网站上的一个页面,它成功地完成了。看来Angular2不再自动路由。我仍然通过MVC('Home/Index')触及Home Controller和Home Index.cshtml视图,所以这看起来像是一个Angular2问题。
这是我的angular2路由看起来像。
`
RouterModule.forRoot([
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'counter', component: CounterComponent },
{ path: 'fetch-data', component: FetchDataComponent },
{ path: 'bryterUsers', component: BryterUsersComponent },
{ path: 'adminUsers', component: AdminUsersComponent },
{ path: 'retailers', component: RetailersComponent },
{ path: 'providers', component: ProvidersComponent },
{ path: '**', redirectTo: 'home' }
])`
UPDATE2:我现在不能再导航到任何其他页面。无论我走到哪里,我都会得到'窗口未定义'的错误。我的代码中没有改变任何内容。我完全被难住了。任何帮助将不胜感激。
没有真正使用的解决方案,但黑客攻击。这会禁用服务器端呈现。 – Ahmad