我是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