疑難排解 Azure App Service 和 IIS 上的 ASP.NET CoreTroubleshoot ASP.NET Core on Azure App Service and IIS

By Luke LathamJustin KotalikBy Luke Latham and Justin Kotalik

本文提供有關一般應用程式啟動錯誤的資訊, 以及如何在將應用程式部署至 Azure App Service 或 IIS 時診斷錯誤的指示:This article provides information on common app startup errors and instructions on how to diagnose errors when an app is deployed to Azure App Service or IIS:

應用程式啟動錯誤App startup errors
說明常見的啟動 HTTP 狀態碼案例。Explains common startup HTTP status code scenarios.

針對 Azure App Service 進行疑難排解Troubleshoot on Azure App Service
提供部署至 Azure App Service 之應用程式的疑難排解建議。Provides troubleshooting advice for apps deployed to Azure App Service.

針對 IIS 進行疑難排解Troubleshoot on IIS
提供部署至 IIS 或在本機 IIS Express 上執行之應用程式的疑難排解建議。Provides troubleshooting advice for apps deployed to IIS or running on IIS Express locally. 本指南適用于 Windows Server 和 Windows 桌面部署。The guidance applies to both Windows Server and Windows desktop deployments.

清除套件快取Clear package caches
說明當一致封裝在執行主要升級或變更封裝版本時, 中斷應用程式時該怎麼辦。Explains what to do when incoherent packages break an app when performing major upgrades or changing package versions.

其他資源Additional resources
列出其他疑難排解主題。Lists additional troubleshooting topics.

應用程式啟動錯誤App startup errors

在 Visual Studio 中,進行偵錯時,ASP.NET Core 專案會預設為 IIS Express 裝載環境。In Visual Studio, an ASP.NET Core project defaults to IIS Express hosting during debugging. 使用本主題中的建議, 可以診斷在本機進行偵錯工具時所發生的502.5-進程失敗500.30 啟動失敗A 502.5 - Process Failure or a 500.30 - Start Failure that occurs when debugging locally can be diagnosed using the advice in this topic.

在 Visual Studio 中,進行偵錯時,ASP.NET Core 專案會預設為 IIS Express 裝載環境。In Visual Studio, an ASP.NET Core project defaults to IIS Express hosting during debugging. 使用本主題中的建議, 可以診斷本機上的偵錯工具發生的502.5 進程失敗A 502.5 Process Failure that occurs when debugging locally can be diagnosed using the advice in this topic.

403.14 禁止403.14 Forbidden

應用程式無法啟動。The app fails to start. 會記錄下列錯誤:The following error is logged:

The Web server is configured to not list the contents of this directory.

此錯誤通常是因為主控系統上的部署中斷所造成,其中包括下列任何一種情況:The error is usually caused by a broken deployment on the hosting system, which includes any of the following scenarios:

  • 應用程式會部署到裝載系統上錯誤的資料夾。The app is deployed to the wrong folder on the hosting system.
  • 部署進程無法將應用程式的所有檔案和資料夾移到主控系統上的部署資料夾。The deployment process failed to move all of the app's files and folders to the deployment folder on the hosting system.
  • 部署中遺漏web.config檔案,或web.config檔案內容的格式不正確。The web.config file is missing from the deployment, or the web.config file contents are malformed.

請執行下列步驟:Perform the following steps:

  1. 刪除主控系統上部署資料夾中的所有檔案和資料夾。Delete all of the files and folders from the deployment folder on the hosting system.
  2. 使用一般部署方法(例如 Visual Studio、PowerShell 或手動部署),將應用程式的 [發佈] 資料夾的內容重新部署至主機系統:Redeploy the contents of the app's publish folder to the hosting system using your normal method of deployment, such as Visual Studio, PowerShell, or manual deployment:
    • 請確認web.config檔案存在於部署中,而且其內容正確。Confirm that the web.config file is present in the deployment and that its contents are correct.
    • 在 Azure App Service 上裝載時,請確認應用程式已部署至D:\home\site\wwwroot資料夾。When hosting on Azure App Service, confirm that the app is deployed to the D:\home\site\wwwroot folder.
    • 當應用程式由 IIS 裝載時,請確認應用程式已部署到 iis管理員的 [基本設定] 中所顯示的 iis實體路徑When the app is hosted by IIS, confirm that the app is deployed to the IIS Physical path shown in IIS Manager's Basic Settings.
  3. 藉由比較主控系統上的部署與專案 [發行] 資料夾的內容,確認已部署所有應用程式的檔案和資料夾。Confirm that all of the app's files and folders are deployed by comparing the deployment on the hosting system to the contents of the project's publish folder.

如需已發佈之 ASP.NET Core 應用程式佈建的詳細資訊, ASP.NET Core 目錄結構請參閱。For more information on the layout of a published ASP.NET Core app, see ASP.NET Core 目錄結構. 如需web.config檔案的詳細資訊,請參閱ASP.NET Core 模組For more information on the web.config file, see ASP.NET Core 模組.

500 內部伺服器錯誤500 Internal Server Error

應用程式啟動,但有錯誤導致伺服器無法完成要求。The app starts, but an error prevents the server from fulfilling the request.

此錯誤是在啟動或建立回應時,在應用程式的程式碼內發生。This error occurs within the app's code during startup or while creating a response. 回應可能未包含任何內容,或是回應可能在瀏覽器中以「500 內部伺服器錯誤」的形式出現。The response may contain no content, or the response may appear as a 500 Internal Server Error in the browser. 「應用程式事件記錄檔」通常會指出該應用程式已正常啟動。The Application Event Log usually states that the app started normally. 從伺服器的觀點來看,這是正確的。From the server's perspective, that's correct. 應用程式已啟動,但無法產生有效的回應。The app did start, but it can't generate a valid response. 在伺服器上的命令提示字元中執行應用程式, 或啟用 ASP.NET Core 模組 stdout 記錄檔, 以針對問題進行疑難排解。Run the app at a command prompt on the server or enable the ASP.NET Core Module stdout log to troubleshoot the problem.

500.0 同處理序處理常式載入失敗500.0 In-Process Handler Load Failure

背景工作處理序失敗。The worker process fails. 應用程式未啟動。The app doesn't start.

ASP.NET Core 模組找不到 .NET Core CLR,而且找不到同進程要求處理常式(aspnetcorev2_inprocess .dll)。The ASP.NET Core Module fails to find the .NET Core CLR and find the in-process request handler (aspnetcorev2_inprocess.dll). 請檢查︰Check that:

500.0 跨處理序處理常式載入失敗500.0 Out-Of-Process Handler Load Failure

背景工作處理序失敗。The worker process fails. 應用程式未啟動。The app doesn't start.

ASP.NET Core 模組找不到跨進程主控要求處理常式。The ASP.NET Core Module fails to find the out-of-process hosting request handler. 請確定 aspnetcorev2_outofprocess.dll 出現在子資料夾中,且位於 aspnetcorev2.dll 旁。Make sure the aspnetcorev2_outofprocess.dll is present in a subfolder next to aspnetcorev2.dll.

500.0 同處理序處理常式載入失敗500.0 In-Process Handler Load Failure

背景工作處理序失敗。The worker process fails. 應用程式未啟動。The app doesn't start.

載入ASP.NET Core 模組元件時發生未知的錯誤。An unknown error occurred loading ASP.NET Core Module components. 採取下列其中一個動作:Take one of the following actions:

500.30 同處理序啟動失敗500.30 In-Process Startup Failure

背景工作處理序失敗。The worker process fails. 應用程式未啟動。The app doesn't start.

ASP.NET Core 模組嘗試啟動 .NET Core CLR 同進程, 但無法啟動。The ASP.NET Core Module attempts to start the .NET Core CLR in-process, but it fails to start. 通常會從應用程式事件記錄檔中的專案和 ASP.NET Core 模組 stdout 記錄檔中判斷進程啟動失敗的原因。The cause of a process startup failure can usually be determined from entries in the Application Event Log and the ASP.NET Core Module stdout log.

因為目標 ASP.NET Core 共用架構的版本不存在,導致應用程式設定錯誤是常見的失敗狀況。A common failure condition is the app is misconfigured due to targeting a version of the ASP.NET Core shared framework that isn't present. 請檢查安裝在目標機器上的 ASP.NET Core 共用架構版本為何。Check which versions of the ASP.NET Core shared framework are installed on the target machine.

500.31 ANCM 找不到原生相依性500.31 ANCM Failed to Find Native Dependencies

背景工作處理序失敗。The worker process fails. 應用程式未啟動。The app doesn't start.

ASP.NET Core 模組嘗試在同進程中啟動 .net Core 執行時間, 但無法啟動。The ASP.NET Core Module attempts to start the .NET Core runtime in-process, but it fails to start. 此啟動失敗的最常見原因是當 Microsoft.NETCore.AppMicrosoft.AspNetCore.App 執行階段未安裝時。The most common cause of this startup failure is when the Microsoft.NETCore.App or Microsoft.AspNetCore.App runtime isn't installed. 如果應用程式部署至目標 ASP.NET Core 3.0,但電腦上無該版本,就會發生此錯誤。If the app is deployed to target ASP.NET Core 3.0 and that version doesn't exist on the machine, this error occurs. 範例錯誤訊息如下:An example error message follows:

The specified framework 'Microsoft.NETCore.App', version '3.0.0' was not found.
  - The following frameworks were found:
      2.2.1 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App]
      3.0.0-preview5-27626-15 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App]
      3.0.0-preview6-27713-13 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App]
      3.0.0-preview6-27714-15 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App]
      3.0.0-preview6-27723-08 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App]

錯誤訊息會列出所有已安裝 .NET Core 版本和應用程式所要求的版本。The error message lists all the installed .NET Core versions and the version requested by the app. 若要修正此錯誤,請使用以下其中一種方法:To fix this error, either:

  • 在電腦上安裝適當的 .NET Core 版本。Install the appropriate version of .NET Core on the machine.
  • 將應用程式的目標 .NET Core 版本變更為電腦上版本。Change the app to target a version of .NET Core that's present on the machine.
  • 將應用程式發佈為自封式部署Publish the app as a self-contained deployment.

在開發過程中執行時 (ASPNETCORE_ENVIRONMENT 環境變數設定為 Development),特定的錯誤會寫入至 HTTP 回應。When running in development (the ASPNETCORE_ENVIRONMENT environment variable is set to Development), the specific error is written to the HTTP response. 在應用程式事件記錄檔中也可以找到進程啟動失敗的原因。The cause of a process startup failure is also found in the Application Event Log.

500.32 ANCM 無法載入 dll500.32 ANCM Failed to Load dll

背景工作處理序失敗。The worker process fails. 應用程式未啟動。The app doesn't start.

此錯誤最常見原因是針對不相容的處理器架構發佈應用程式。The most common cause for this error is that the app is published for an incompatible processor architecture. 如果背景工作處理序執行為 32 位元應用程式,而此應用程式已發佈至目標 64 位元,就會發生此錯誤。If the worker process is running as a 32-bit app and the app was published to target 64-bit, this error occurs.

若要修正此錯誤,請使用以下其中一種方法:To fix this error, either:

  • 針對相同的處理器架構,將應用程式重新發佈為背景工作處理序。Republish the app for the same processor architecture as the worker process.
  • 將應用程式發佈為架構相依部署Publish the app as a framework-dependent deployment.

500.33 ANCM 要求處理常式載入失敗500.33 ANCM Request Handler Load Failure

背景工作處理序失敗。The worker process fails. 應用程式未啟動。The app doesn't start.

應用程式未參考 Microsoft.AspNetCore.App 架構。The app didn't reference the Microsoft.AspNetCore.App framework. ASP.NET Core 模組只能主控Microsoft.AspNetCore.App以架構為目標的應用程式。Only apps targeting the Microsoft.AspNetCore.App framework can be hosted by the ASP.NET Core Module.

若要修正這個錯誤,請確認應用程式以 Microsoft.AspNetCore.App 架構為目標。To fix this error, confirm that the app is targeting the Microsoft.AspNetCore.App framework. 檢查 .runtimeconfig.json 以驗證應用程式是否以該架構為目標。Check the .runtimeconfig.json to verify the framework targeted by the app.

500.34 ANCM 不支援混合式裝載模型500.34 ANCM Mixed Hosting Models Not Supported

背景工作處理序無法在相同的程序中執行同處理序應用程式和跨處理序應用程式。The worker process can't run both an in-process app and an out-of-process app in the same process.

若要修正這個錯誤,請在不同的 IIS 應用程式集區中執行應用程式。To fix this error, run apps in separate IIS application pools.

500.35 ANCM 同一程序中有多個同處理序應用程式500.35 ANCM Multiple In-Process Applications in same Process

背景工作處理序無法在相同的程序中執行同處理序應用程式和跨處理序應用程式。The worker process can't run both an in-process app and an out-of-process app in the same process.

若要修正這個錯誤,請在不同的 IIS 應用程式集區中執行應用程式。To fix this error, run apps in separate IIS application pools.

500.36 ANCM 跨處理序處理常式載入失敗500.36 ANCM Out-Of-Process Handler Load Failure

跨處理序要求處理常式 aspnetcorev2_outofprocess.dll 不在 aspnetcorev2.dll 檔案旁邊。The out-of-process request handler, aspnetcorev2_outofprocess.dll, isn't next to the aspnetcorev2.dll file. 這表示ASP.NET Core 模組安裝損毀。This indicates a corrupted installation of the ASP.NET Core Module.

若要修正這個錯誤,請修復 .NET Core 裝載套件組合 (適用於 IIS) 或 Visual Studio (適用於 IIS Express) 安裝。To fix this error, repair the installation of the .NET Core Hosting Bundle (for IIS) or Visual Studio (for IIS Express).

500.37 ANCM 無法在啟動時間限制內啟動500.37 ANCM Failed to Start Within Startup Time Limit

ANCM 無法在提供的啟動時間限制內啟動。ANCM failed to start within the provied startup time limit. 根據預設,逾時值為 120 秒。By default, the timeout is 120 seconds.

在同一部電腦上啟動大量的應用程式時,就會發生此錯誤。This error can occur when starting a large number of apps on the same machine. 檢查伺服器在啟動期間是否出現 CPU/記憶體的使用量尖峰。Check for CPU/Memory usage spikes on the server during startup. 多個應用程式的啟動程序可能需要交錯進行。You may need to stagger the startup process of multiple apps.

502.5 處理序失敗502.5 Process Failure

背景工作處理序失敗。The worker process fails. 應用程式未啟動。The app doesn't start.

ASP.NET Core 模組嘗試啟動背景工作處理序,但無法啟動。The ASP.NET Core Module attempts to start the worker process but it fails to start. 通常會從應用程式事件記錄檔中的專案和 ASP.NET Core 模組 stdout 記錄檔中判斷進程啟動失敗的原因。The cause of a process startup failure can usually be determined from entries in the Application Event Log and the ASP.NET Core Module stdout log.

因為目標 ASP.NET Core 共用架構的版本不存在,導致應用程式設定錯誤是常見的失敗狀況。A common failure condition is the app is misconfigured due to targeting a version of the ASP.NET Core shared framework that isn't present. 請檢查安裝在目標機器上的 ASP.NET Core 共用架構版本為何。Check which versions of the ASP.NET Core shared framework are installed on the target machine. 「共用的架構」是一組安裝於電腦上且由 Microsoft.AspNetCore.App 之類的中繼套件所參考的組件 ( .dll 檔案)。The shared framework is the set of assemblies (.dll files) that are installed on the machine and referenced by a metapackage such as Microsoft.AspNetCore.App. 中繼套件參考可以指定最低必要版本。The metapackage reference can specify a minimum required version. 如需詳細資訊,請參閱共用的架構 (英文)。For more information, see The shared framework.

當裝載或應用程式設定錯誤造成背景工作處理序發生失敗時,會傳回 [502.5 處理序失敗] 錯誤頁面:The 502.5 Process Failure error page is returned when a hosting or app misconfiguration causes the worker process to fail:

無法啟動應用程式 (ErrorCode '0x800700c1')Failed to start application (ErrorCode '0x800700c1')

EventID: 1010
Source: IIS AspNetCore Module V2
Failed to start application '/LM/W3SVC/6/ROOT/', ErrorCode '0x800700c1'.

應用程式無法啟動,因為無法載入應用程式的組件 ( .dll)。The app failed to start because the app's assembly (.dll) couldn't be loaded.

當已發行的應用程式與 w3wp/iisexpress 處理序之間出現位元不符的情況時,就會發生此錯誤。This error occurs when there's a bitness mismatch between the published app and the w3wp/iisexpress process.

確認應用程式集區的 32 位元設定正確:Confirm that the app pool's 32-bit setting is correct:

  1. 在 IIS 管理員的 [應用程式集區] 中,選取應用程式集區。Select the app pool in IIS Manager's Application Pools.
  2. 在 [動作] 面板中,選取 [編輯應用程式集區] 下的 [進階設定]。Select Advanced Settings under Edit Application Pool in the Actions panel.
  3. 設定 [啟用 32 位元應用程式]:Set Enable 32-Bit Applications:
    • 如果部署 32 位元 (x86) 應用程式,請將值設定為 TrueIf deploying a 32-bit (x86) app, set the value to True.
    • 如果部署 64 位元 (x64) 應用程式,請將值設定為 FalseIf deploying a 64-bit (x64) app, set the value to False.

確認專案檔中的<Platform> MSBuild 屬性和應用程式的已發佈位之間沒有衝突。Confirm that there isn't a conflict between a <Platform> MSBuild property in the project file and the published bitness of the app.

連線重設Connection reset

如果是在傳送標頭之後才發生錯誤,則當發生錯誤時,伺服器已來不及傳送「500 內部伺服器錯誤」。If an error occurs after the headers are sent, it's too late for the server to send a 500 Internal Server Error when an error occurs. 通常是在將回應的複雜物件序列化的期間發生錯誤時,會發生此錯誤。This often happens when an error occurs during the serialization of complex objects for a response. 這類錯誤會在用戶端上顯示為「連線重設」錯誤。This type of error appears as a connection reset error on the client. 應用程式記錄可協助針對這些類型的錯誤進行疑難排解。Application logging can help troubleshoot these types of errors.

預設啟動限制Default startup limits

ASP.NET Core 模組是以120秒的預設startupTimeLimit來設定。The ASP.NET Core Module is configured with a default startupTimeLimit of 120 seconds. 保留預設值時,在模組記錄處理序失敗之前,應用程式最多可花費兩分鐘來進行啟動。When left at the default value, an app may take up to two minutes to start before the module logs a process failure. 如需有關設定模組的資訊,請參閱 aspNetCore 元素的屬性For information on configuring the module, see Attributes of the aspNetCore element.

針對 Azure App Service 進行疑難排解Troubleshoot on Azure App Service

重要

ASP.NET Core 預覽版本與 Azure App ServiceASP.NET Core preview releases with Azure App Service

根據預設,ASP.NET Core 預覽版本不會部署至 Azure App Service。ASP.NET Core preview releases aren't deployed to Azure App Service by default. 若要裝載使用 ASP.NET Core 預覽版本的應用程式,請參閱將 ASP.NET Core 預覽版本部署至 Azure App ServiceTo host an app that uses an ASP.NET Core preview release, see Deploy ASP.NET Core preview release to Azure App Service.

應用程式事件記錄檔 (Azure App Service)Application Event Log (Azure App Service)

若要存取「應用程式事件記錄檔」,請使用 Azure 入口網站中的 [診斷並解決問題] 刀鋒視窗:To access the Application Event Log, use the Diagnose and solve problems blade in the Azure portal:

  1. 在 Azure 入口網站的 [應用程式服務] 中,開啟應用程式。In the Azure portal, open the app in App Services.
  2. 選取 [診斷並解決問題]。Select Diagnose and solve problems.
  3. 選取 [診斷工具] 標題。Select the Diagnostic Tools heading.
  4. 在 [支援工具] 下,選取 [應用程式事件] 按鈕。Under Support Tools, select the Application Events button.
  5. 檢查 [來源] 資料行中 IIS AspNetCoreModuleIIS AspNetCoreModule V2 項目所提供的最新錯誤。Examine the latest error provided by the IIS AspNetCoreModule or IIS AspNetCoreModule V2 entry in the Source column.

除了使用 [診斷並解決問題] 刀鋒視窗之外,也可以使用 Kudu 來直接檢查「應用程式事件記錄檔」:An alternative to using the Diagnose and solve problems blade is to examine the Application Event Log file directly using Kudu:

  1. 在 [開發工具] 區域中,開啟 [進階工具]。Open Advanced Tools in the Development Tools area. 選取 [執行→] 按鈕。Select the Go→ button. Kudu 主控台會在新的瀏覽器索引標籤或視窗中開啟。The Kudu console opens in a new browser tab or window.
  2. 使用頁面頂端的導覽列,開啟 [偵錯主控台],然後選取 [CMD]。Using the navigation bar at the top of the page, open Debug console and select CMD.
  3. 開啟 [LogFiles] 資料夾。Open the LogFiles folder.
  4. 選取 eventlog.xml 檔案旁邊的鉛筆圖示。Select the pencil icon next to the eventlog.xml file.
  5. 檢查記錄檔。Examine the log. 捲動至記錄檔的底部以查看最新事件。Scroll to the bottom of the log to see the most recent events.

在 Kudu 主控台中執行應用程式Run the app in the Kudu console

許多啟動錯誤不會在「應用程式事件記錄檔」中產生實用的資訊。Many startup errors don't produce useful information in the Application Event Log. 您可以在 Kudu「遠端執行主控台」中執行應用程式來探索錯誤:You can run the app in the Kudu Remote Execution Console to discover the error:

  1. 在 [開發工具] 區域中,開啟 [進階工具]。Open Advanced Tools in the Development Tools area. 選取 [執行→] 按鈕。Select the Go→ button. Kudu 主控台會在新的瀏覽器索引標籤或視窗中開啟。The Kudu console opens in a new browser tab or window.
  2. 使用頁面頂端的導覽列,開啟 [偵錯主控台],然後選取 [CMD]。Using the navigation bar at the top of the page, open Debug console and select CMD.

測試 32 位元 (x86) 應用程式Test a 32-bit (x86) app

目前的版本Current release

  1. cd d:\home\site\wwwroot
  2. 執行應用程式:Run the app:

來自應用程式的主控台輸出若有顯示任何錯誤,就會透過管道傳送給 Kudu 主控台。The console output from the app, showing any errors, is piped to the Kudu console.

在預覽版本上執行的 Framework 相依部署Framework-dependent deployment running on a preview release

要求安裝 ASP.NET Core {VERSION} (x86) 執行階段網站延伸模組。Requires installing the ASP.NET Core {VERSION} (x86) Runtime site extension.

  1. cd D:\home\SiteExtensions\AspNetCoreRuntime.{X.Y}.x32 ({X.Y} 是執行階段版本)cd D:\home\SiteExtensions\AspNetCoreRuntime.{X.Y}.x32 ({X.Y} is the runtime version)
  2. 執行應用程式:dotnet \home\site\wwwroot\{ASSEMBLY NAME}.dllRun the app: dotnet \home\site\wwwroot\{ASSEMBLY NAME}.dll

來自應用程式的主控台輸出若有顯示任何錯誤,就會透過管道傳送給 Kudu 主控台。The console output from the app, showing any errors, is piped to the Kudu console.

測試 64 位元 (x64) 應用程式Test a 64-bit (x64) app

目前的版本Current release

  • 如果應用程式是 64 位元 (x64) 架構相依部署If the app is a 64-bit (x64) framework-dependent deployment:
    1. cd D:\Program Files\dotnet
    2. 執行應用程式:dotnet \home\site\wwwroot\{ASSEMBLY NAME}.dllRun the app: dotnet \home\site\wwwroot\{ASSEMBLY NAME}.dll
  • 如果應用程式是自封式部署If the app is a self-contained deployment:
    1. cd D:\home\site\wwwroot
    2. 執行應用程式:{ASSEMBLY NAME}.exeRun the app: {ASSEMBLY NAME}.exe

來自應用程式的主控台輸出若有顯示任何錯誤,就會透過管道傳送給 Kudu 主控台。The console output from the app, showing any errors, is piped to the Kudu console.

在預覽版本上執行的 Framework 相依部署Framework-dependent deployment running on a preview release

要求安裝 ASP.NET Core {VERSION} (x64) 執行階段網站延伸模組。Requires installing the ASP.NET Core {VERSION} (x64) Runtime site extension.

  1. cd D:\home\SiteExtensions\AspNetCoreRuntime.{X.Y}.x64 ({X.Y} 是執行階段版本)cd D:\home\SiteExtensions\AspNetCoreRuntime.{X.Y}.x64 ({X.Y} is the runtime version)
  2. 執行應用程式:dotnet \home\site\wwwroot\{ASSEMBLY NAME}.dllRun the app: dotnet \home\site\wwwroot\{ASSEMBLY NAME}.dll

來自應用程式的主控台輸出若有顯示任何錯誤,就會透過管道傳送給 Kudu 主控台。The console output from the app, showing any errors, is piped to the Kudu console.

ASP.NET Core 模組 stdout 記錄檔 (Azure App Service)ASP.NET Core Module stdout log (Azure App Service)

ASP.NET Core 模組 stdout 記錄檔通常會記錄「應用程式事件記錄檔」中所沒有的實用訊息。The ASP.NET Core Module stdout log often records useful error messages not found in the Application Event Log. 啟用及檢視 stdout 記錄檔:To enable and view stdout logs:

  1. 在 Azure 入口網站中,瀏覽至 [診斷並解決問題] 刀鋒視窗。Navigate to the Diagnose and solve problems blade in the Azure portal.
  2. 在 [選取問題類別] 底下,選取 [Web 應用程式停止運作] 按鈕。Under SELECT PROBLEM CATEGORY, select the Web App Down button.
  3. 在 [建議的解決方案] > [啟用 Stdout 記錄檔重新導向] 底下,選取用來開啟 Kudu 主控台以編輯 Web.Config 的按鈕。Under Suggested Solutions > Enable Stdout Log Redirection, select the button to Open Kudu Console to edit Web.Config.
  4. 在 Kudu [診斷主控台] 中,將資料夾開啟至路徑 [site] > [wwwroot]。In the Kudu Diagnostic Console, open the folders to the path site > wwwroot. 向下捲動以顯露位於清單底部的 web.config 檔案。Scroll down to reveal the web.config file at the bottom of the list.
  5. 按一下 web.config 檔案旁邊的鉛筆圖示。Click the pencil icon next to the web.config file.
  6. stdoutLogEnabled 設定為 true,並將 stdoutLogFile 路徑變更為:\\?\%home%\LogFiles\stdoutSet stdoutLogEnabled to true and change the stdoutLogFile path to: \\?\%home%\LogFiles\stdout.
  7. 選取 [儲存] 以儲存已更新的 web.config 檔案。Select Save to save the updated web.config file.
  8. 對應用程式發出要求。Make a request to the app.
  9. 返回 Azure 入口網站。Return to the Azure portal. 選取 [開發工具] 區域中的 [進階工具] 刀鋒視窗。Select the Advanced Tools blade in the DEVELOPMENT TOOLS area. 選取 [執行→] 按鈕。Select the Go→ button. Kudu 主控台會在新的瀏覽器索引標籤或視窗中開啟。The Kudu console opens in a new browser tab or window.
  10. 使用頁面頂端的導覽列,開啟 [偵錯主控台],然後選取 [CMD]。Using the navigation bar at the top of the page, open Debug console and select CMD.
  11. 選取 [LogFiles] 資料夾。Select the LogFiles folder.
  12. 檢查 [修改時間] 資料行,然後選取鉛筆圖示來編輯修改日期最新的 stdout 記錄檔。Inspect the Modified column and select the pencil icon to edit the stdout log with the latest modification date.
  13. 當記錄檔開啟時,會顯示錯誤。When the log file opens, the error is displayed.

完成疑難排解時,請停用 stdout 記錄:Disable stdout logging when troubleshooting is complete:

  1. 在 Kudu [診斷主控台] 中,返回路徑 [site] > [wwwroot] 以顯露 web.config 檔案。In the Kudu Diagnostic Console, return to the path site > wwwroot to reveal the web.config file. 再次選取鉛筆圖示來開啟 web.config 檔案。Open the web.config file again by selecting the pencil icon.
  2. stdoutLogEnabled 設定為 falseSet stdoutLogEnabled to false.
  3. 選取 [儲存] 以儲存檔案。Select Save to save the file.

如需詳細資訊,請參閱 ASP.NET Core 模組For more information, see ASP.NET Core 模組.

警告

如果無法停用 stdout 記錄檔,可能會造成應用程式或伺服器發生失敗。Failure to disable the stdout log can lead to app or server failure. 因為它並沒有記錄檔大小或數量上的限制。There's no limit on log file size or the number of log files created. 請只在針對應用程式啟動問題進行疑難排解時,才使用 stdout 記錄。Only use stdout logging to troubleshoot app startup problems.

針對 ASP.NET Core 應用程式啟動後的一般記錄,請使用會限制記錄檔大小並輪替記錄檔的記錄程式庫。For general logging in an ASP.NET Core app after startup, use a logging library that limits log file size and rotates logs. 如需詳細資訊,請參閱協力廠商記錄提供者For more information, see third-party logging providers.

ASP.NET Core 模組的 debug 記錄檔 (Azure App Service)ASP.NET Core Module debug log (Azure App Service)

ASP.NET Core 模組偵錯記錄提供 ASP.NET Core 模組中其他且更深入的記錄。The ASP.NET Core Module debug log provides additional, deeper logging from the ASP.NET Core Module. 啟用及檢視 stdout 記錄檔:To enable and view stdout logs:

  1. 若要啟用增強型診斷記錄,請執行下列任一動作:To enable the enhanced diagnostic log, perform either of the following:
    • 遵循增強型診斷記錄中的指示,來設定應用程式進行增強型診斷記錄。Follow the instructions in Enhanced diagnostic logs to configure the app for an enhanced diagnostic logging. 重新部署應用程式。Redeploy the app.
    • 使用 Kudu 主控台,將增強型診斷記錄中所顯示的 <handlerSettings> 新增至即時應用程式的 web.config 檔案:Add the <handlerSettings> shown in Enhanced diagnostic logs to the live app's web.config file using the Kudu console:
      1. 在 [開發工具] 區域中,開啟 [進階工具]。Open Advanced Tools in the Development Tools area. 選取 [執行→] 按鈕。Select the Go→ button. Kudu 主控台會在新的瀏覽器索引標籤或視窗中開啟。The Kudu console opens in a new browser tab or window.
      2. 使用頁面頂端的導覽列,開啟 [偵錯主控台],然後選取 [CMD]。Using the navigation bar at the top of the page, open Debug console and select CMD.
      3. 將資料夾開啟至路徑 [site] > [wwwroot]。Open the folders to the path site > wwwroot. 選取鉛筆圖示來編輯 web.config 檔案。Edit the web.config file by selecting the pencil button. 新增 <handlerSettings> 區段,如增強型診斷記錄中所示。Add the <handlerSettings> section as shown in Enhanced diagnostic logs. 選取 [儲存] 按鈕。Select the Save button.
  2. 在 [開發工具] 區域中,開啟 [進階工具]。Open Advanced Tools in the Development Tools area. 選取 [執行→] 按鈕。Select the Go→ button. Kudu 主控台會在新的瀏覽器索引標籤或視窗中開啟。The Kudu console opens in a new browser tab or window.
  3. 使用頁面頂端的導覽列,開啟 [偵錯主控台],然後選取 [CMD]。Using the navigation bar at the top of the page, open Debug console and select CMD.
  4. 將資料夾開啟至路徑 [site] > [wwwroot]。Open the folders to the path site > wwwroot. 如果未提供 aspnetcore-debug.log 檔案的路徑,該檔案會顯示在清單中。If you didn't supply a path for the aspnetcore-debug.log file, the file appears in the list. 如果已提供路徑,請巡覽至記錄檔的位置。If you supplied a path, navigate to the location of the log file.
  5. 使用檔案名稱旁的鉛筆圖示來開啟記錄檔。Open the log file with the pencil button next to the file name.

完成疑難排解時,請停用偵錯記錄:Disable debug logging when troubleshooting is complete:

若要停用增強型偵錯記錄,請執行下列任一動作:To disable the enhanced debug log, perform either of the following:

  • web.config 檔案本機移除 <handlerSettings> 並重新部署應用程式。Remove the <handlerSettings> from the web.config file locally and redeploy the app.
  • 使用 Kudu 主控台來編輯 web.config 檔案並移除 <handlerSettings> 區段。Use the Kudu console to edit the web.config file and remove the <handlerSettings> section. 儲存檔案。Save the file.

如需詳細資訊,請參閱 ASP.NET Core 模組For more information, see ASP.NET Core 模組.

警告

無法停用偵錯記錄,可能會造成應用程式或伺服器發生失敗。Failure to disable the debug log can lead to app or server failure. 記錄檔大小沒有任何限制。There's no limit on log file size. 請只在針對應用程式啟動問題進行疑難排解時,才使用偵錯記錄。Only use debug logging to troubleshoot app startup problems.

針對 ASP.NET Core 應用程式啟動後的一般記錄,請使用會限制記錄檔大小並輪替記錄檔的記錄程式庫。For general logging in an ASP.NET Core app after startup, use a logging library that limits log file size and rotates logs. 如需詳細資訊,請參閱協力廠商記錄提供者For more information, see third-party logging providers.

緩慢或懸掛應用程式 (Azure App Service)Slow or hanging app (Azure App Service)

當應用程式針對要求回應緩慢或無回應時,請參閱下列文章:When an app responds slowly or hangs on a request, see the following articles:

監視刀鋒視窗Monitoring blades

監視刀鋒視窗為本主題稍早所述的方法提供替代的疑難排解體驗。Monitoring blades provide an alternative troubleshooting experience to the methods described earlier in the topic. 這些刀鋒視窗可用來診斷 500 系列的錯誤。These blades can be used to diagnose 500-series errors.

請確認已安裝 ASP.NET Core 延伸模組。Confirm that the ASP.NET Core Extensions are installed. 如果未安裝這些延伸模組,請手動安裝:If the extensions aren't installed, install them manually:

  1. 在 [開發工具] 刀鋒視窗區段中,選取 [延伸模組] 刀鋒視窗。In the DEVELOPMENT TOOLS blade section, select the Extensions blade.
  2. [ASP.NET Core 延伸模組] 應該會出現在清單中。The ASP.NET Core Extensions should appear in the list.
  3. 如果未安裝這些延伸模組,請選取 [新增] 按鈕。If the extensions aren't installed, select the Add button.
  4. 從清單中選擇 [ASP.NET Core 延伸模組]。Choose the ASP.NET Core Extensions from the list.
  5. 選取 [確定] 以接受法律條款。Select OK to accept the legal terms.
  6. 在 [新增延伸模組] 刀鋒視窗上,選取 [確定]。Select OK on the Add extension blade.
  7. 成功安裝延伸模組時,會有資訊快顯訊息提供指示。An informational pop-up message indicates when the extensions are successfully installed.

如果未啟用 stdout 記錄,請依照下列步驟進行操作:If stdout logging isn't enabled, follow these steps:

  1. 在 Azure 入口網站中,選取 [開發工具] 區域中的 [進階工具] 刀鋒視窗。In the Azure portal, select the Advanced Tools blade in the DEVELOPMENT TOOLS area. 選取 [執行→] 按鈕。Select the Go→ button. Kudu 主控台會在新的瀏覽器索引標籤或視窗中開啟。The Kudu console opens in a new browser tab or window.
  2. 使用頁面頂端的導覽列,開啟 [偵錯主控台],然後選取 [CMD]。Using the navigation bar at the top of the page, open Debug console and select CMD.
  3. 將資料夾開啟至路徑 [site] > [wwwroot],然後向下捲動以顯露位於清單底部的 web.config 檔案。Open the folders to the path site > wwwroot and scroll down to reveal the web.config file at the bottom of the list.
  4. 按一下 web.config 檔案旁邊的鉛筆圖示。Click the pencil icon next to the web.config file.
  5. stdoutLogEnabled 設定為 true,並將 stdoutLogFile 路徑變更為:\\?\%home%\LogFiles\stdoutSet stdoutLogEnabled to true and change the stdoutLogFile path to: \\?\%home%\LogFiles\stdout.
  6. 選取 [儲存] 以儲存已更新的 web.config 檔案。Select Save to save the updated web.config file.

繼續接著啟用診斷記錄:Proceed to activate diagnostic logging:

  1. 在 Azure 入口網站中,選取 [診斷記錄檔] 刀鋒視窗。In the Azure portal, select the Diagnostics logs blade.
  2. 選取 [應用程式記錄 (檔案系統)] 和 [詳細錯誤訊息].的 [開啟] 開關。Select the On switch for Application Logging (Filesystem) and Detailed error messages. 選取刀鋒視窗頂端的 [儲存] 按鈕。Select the Save button at the top of the blade.
  3. 若要包含失敗要求追蹤 (也稱為「失敗要求事件緩衝處理」(FREB) 記錄),請選取 [失敗要求的追蹤] 的 [開啟] 開關。To include failed request tracing, also known as Failed Request Event Buffering (FREB) logging, select the On switch for Failed request tracing.
  4. 選取 [記錄資料流] 刀鋒視窗 (列在入口網站中緊接在 [診斷記錄檔] 刀鋒視窗之下)。Select the Log stream blade, which is listed immediately under the Diagnostics logs blade in the portal.
  5. 對應用程式發出要求。Make a request to the app.
  6. 在記錄資料流資料內,會指出錯誤的原因。Within the log stream data, the cause of the error is indicated.

完成疑難排解時,請務必停用 stdout 記錄。Be sure to disable stdout logging when troubleshooting is complete.

檢視失敗要求追蹤記錄檔 (FREB 記錄檔):To view the failed request tracing logs (FREB logs):

  1. 在 Azure 入口網站中,瀏覽至 [診斷並解決問題] 刀鋒視窗。Navigate to the Diagnose and solve problems blade in the Azure portal.
  2. 從資訊看板的 [支援工具] 區域中,選取 [失敗要求追蹤記錄檔]。Select Failed Request Tracing Logs from the SUPPORT TOOLS area of the sidebar.

如需詳細資訊,請參閱<在 Azure App Service 中針對 Web 應用程式啟用診斷記錄功能>主題的<失敗要求追蹤>一節Azure Web 應用程式的應用程式效能常見問題集:如何開啟失敗要求追蹤See Failed request traces section of the Enable diagnostics logging for web apps in Azure App Service topic and the Application performance FAQs for Web Apps in Azure: How do I turn on failed request tracing? for more information.

如需詳細資訊,請參閱在 Azure App Service 中針對 Web 應用程式啟用診斷記錄功能For more information, see Enable diagnostics logging for web apps in Azure App Service.

警告

如果無法停用 stdout 記錄檔,可能會造成應用程式或伺服器發生失敗。Failure to disable the stdout log can lead to app or server failure. 因為它並沒有記錄檔大小或數量上的限制。There's no limit on log file size or the number of log files created.

針對 ASP.NET Core 應用程式中的例行性記錄,請使用會限制記錄檔大小並輪替記錄檔的記錄程式庫。For routine logging in an ASP.NET Core app, use a logging library that limits log file size and rotates logs. 如需詳細資訊,請參閱協力廠商記錄提供者For more information, see third-party logging providers.

針對 IIS 進行疑難排解Troubleshoot on IIS

應用程式事件記錄檔 (IIS)Application Event Log (IIS)

存取「應用程式事件記錄檔」:Access the Application Event Log:

  1. 開啟 [開始] 功能表,搜尋事件檢視器,然後選取 [事件檢視器]應用程式。Open the Start menu, search for Event Viewer, and then select the Event Viewer app.
  2. 在 [事件檢視器] 中,開啟 [Windows 記錄] 節點。In Event Viewer, open the Windows Logs node.
  3. 選取 [應用程式] 以開啟「應用程式事件記錄檔」。Select Application to open the Application Event Log.
  4. 搜尋與失敗應用程式相關的錯誤。Search for errors associated with the failing app. 錯誤在 [來源] 資料行中的值會是 IIS AspNetCore ModuleIIS Express AspNetCore ModuleErrors have a value of IIS AspNetCore Module or IIS Express AspNetCore Module in the Source column.

在命令提示字元中執行應用程式Run the app at a command prompt

許多啟動錯誤不會在「應用程式事件記錄檔」中產生實用的資訊。Many startup errors don't produce useful information in the Application Event Log. 您可以藉由在主控系統上的命令提示字元中執行應用程式,來找出一些錯誤的原因。You can find the cause of some errors by running the app at a command prompt on the hosting system.

與 Framework 相依的部署Framework-dependent deployment

如果應用程式是架構相依部署If the app is a framework-dependent deployment:

  1. 在命令提示字元中,瀏覽至部署資料夾,然後使用 dotnet.exe 來執行應用程式組件以執行應用程式。At a command prompt, navigate to the deployment folder and run the app by executing the app's assembly with dotnet.exe. 在下列命令中,請以應用程式組件的名稱取代 <assembly_name>:dotnet .\<assembly_name>.dllIn the following command, substitute the name of the app's assembly for <assembly_name>: dotnet .\<assembly_name>.dll.
  2. 來自應用程式的主控台輸出若有顯示任何錯誤,就會寫入至主控台視窗。The console output from the app, showing any errors, is written to the console window.
  3. 如果是在對應用程式發出要求時發生錯誤,請對 Kestrel 進行接聽的主機和連接埠發出要求。If the errors occur when making a request to the app, make a request to the host and port where Kestrel listens. 如果使用預設主機和連接埠,請對 http://localhost:5000/ 發出要求。Using the default host and post, make a request to http://localhost:5000/. 如果應用程式在 Kestrel 端點位址正常回應,則問題與主機組態有關的機率較大,而與應用程式本身有關的機率較小。If the app responds normally at the Kestrel endpoint address, the problem is more likely related to the hosting configuration and less likely within the app.

自封式部署Self-contained deployment

如果應用程式是自封式部署If the app is a self-contained deployment:

  1. 在命令提示字元中,瀏覽至部署資料夾,然後執行應用程式的可執行檔。At a command prompt, navigate to the deployment folder and run the app's executable. 在下列命令中,請以應用程式組件的名稱取代 <assembly_name>:<assembly_name>.exeIn the following command, substitute the name of the app's assembly for <assembly_name>: <assembly_name>.exe.
  2. 來自應用程式的主控台輸出若有顯示任何錯誤,就會寫入至主控台視窗。The console output from the app, showing any errors, is written to the console window.
  3. 如果是在對應用程式發出要求時發生錯誤,請對 Kestrel 進行接聽的主機和連接埠發出要求。If the errors occur when making a request to the app, make a request to the host and port where Kestrel listens. 如果使用預設主機和連接埠,請對 http://localhost:5000/ 發出要求。Using the default host and post, make a request to http://localhost:5000/. 如果應用程式在 Kestrel 端點位址正常回應,則問題與主機組態有關的機率較大,而與應用程式本身有關的機率較小。If the app responds normally at the Kestrel endpoint address, the problem is more likely related to the hosting configuration and less likely within the app.

ASP.NET Core 模組 stdout 記錄檔 (IIS)ASP.NET Core Module stdout log (IIS)

啟用及檢視 stdout 記錄檔:To enable and view stdout logs:

  1. 瀏覽至主控系統上網站的部署資料夾。Navigate to the site's deployment folder on the hosting system.
  2. 如果 [logs] 資料夾不存在,請建立該資料夾。If the logs folder isn't present, create the folder. 如需有關如何讓 MSBuild 在部署中自動建立 [logs] 資料夾的指示,請參閱目錄結構主題。For instructions on how to enable MSBuild to create the logs folder in the deployment automatically, see the Directory structure topic.
  3. 編輯 web.config 檔案。Edit the web.config file. stdoutLogEnabled 設定為 true,並將 stdoutLogFile 路徑變更為指向 [logs] 資料夾 (例如 .\logs\stdout)。Set stdoutLogEnabled to true and change the stdoutLogFile path to point to the logs folder (for example, .\logs\stdout). 路徑中的 stdout 是記錄檔名稱前置詞。stdout in the path is the log file name prefix. 建立記錄檔時,系統會自動新增時間戳記、處理序識別碼及副檔名。A timestamp, process id, and file extension are added automatically when the log is created. 使用 stdout 作為檔案名稱前置詞時,一般記錄檔會命名為 stdout_20180205184032_5412.logUsing stdout as the file name prefix, a typical log file is named stdout_20180205184032_5412.log.
  4. 請確定您的應用程式集區身分識別具有 logs 資料夾的寫入權限。Ensure your application pool's identity has write permissions to the logs folder.
  5. 儲存已更新的 web.config 檔案。Save the updated web.config file.
  6. 對應用程式發出要求。Make a request to the app.
  7. 瀏覽至 [logs] 資料夾。Navigate to the logs folder. 尋找並開啟最新的 stdout 記錄檔。Find and open the most recent stdout log.
  8. 研究記錄檔以了解錯誤。Study the log for errors.

完成疑難排解時,請停用 stdout 記錄:Disable stdout logging when troubleshooting is complete:

  1. 編輯 web.config 檔案。Edit the web.config file.
  2. stdoutLogEnabled 設定為 falseSet stdoutLogEnabled to false.
  3. 儲存檔案。Save the file.

如需詳細資訊,請參閱 ASP.NET Core 模組For more information, see ASP.NET Core 模組.

警告

如果無法停用 stdout 記錄檔,可能會造成應用程式或伺服器發生失敗。Failure to disable the stdout log can lead to app or server failure. 因為它並沒有記錄檔大小或數量上的限制。There's no limit on log file size or the number of log files created.

針對 ASP.NET Core 應用程式中的例行性記錄,請使用會限制記錄檔大小並輪替記錄檔的記錄程式庫。For routine logging in an ASP.NET Core app, use a logging library that limits log file size and rotates logs. 如需詳細資訊,請參閱協力廠商記錄提供者For more information, see third-party logging providers.

ASP.NET Core 模組的調試記錄檔 (IIS)ASP.NET Core Module debug log (IIS)

將下列處理常式設定新增至應用程式的 web.config 檔案, 以啟用 ASP.NET Core 模組的 debug 記錄檔:Add the following handler settings to the app's web.config file to enable ASP.NET Core Module debug log:

<aspNetCore ...>
  <handlerSettings>
    <handlerSetting name="debugLevel" value="file" />
    <handlerSetting name="debugFile" value="c:\temp\ancm.log" />
  </handlerSettings>
</aspNetCore>

確認為記錄指定的路徑存在,而且應用程式集區的身分識別具有該位置的寫入權限。Confirm that the path specified for the log exists and that the app pool's identity has write permissions to the location.

如需詳細資訊,請參閱 ASP.NET Core 模組For more information, see ASP.NET Core 模組.

啟用開發人員例外頁面Enable the Developer Exception Page

在開發環境中,可以將 ASPNETCORE_ENVIRONMENT 環境變數新增至 web.config 來執行應用程式。The ASPNETCORE_ENVIRONMENT environment variable can be added to web.config to run the app in the Development environment. 只要主機產生器上的 UseEnvironment 不會覆寫應用程式啟動內的環境,設定該環境變數便可允許在應用程式執行時顯示開發人員例外狀況頁面As long as the environment isn't overridden in app startup by UseEnvironment on the host builder, setting the environment variable allows the Developer Exception Page to appear when the app is run.

<aspNetCore processPath="dotnet"
      arguments=".\MyApp.dll"
      stdoutLogEnabled="false"
      stdoutLogFile=".\logs\stdout"
      hostingModel="InProcess">
  <environmentVariables>
    <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
  </environmentVariables>
</aspNetCore>
<aspNetCore processPath="dotnet"
      arguments=".\MyApp.dll"
      stdoutLogEnabled="false"
      stdoutLogFile=".\logs\stdout">
  <environmentVariables>
    <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
  </environmentVariables>
</aspNetCore>

只有在沒有對網際網路公開的暫存和測試伺服器上使用時,才建議為 ASPNETCORE_ENVIRONMENT 設定環境變數。Setting the environment variable for ASPNETCORE_ENVIRONMENT is only recommended for use on staging and testing servers that aren't exposed to the Internet. 進行疑難排解之後,請從 web.config 檔案中移除環境變數。Remove the environment variable from the web.config file after troubleshooting. 如需有關在 web.config 中設定環境變數的資訊,請參閱 aspNetCore 的 environmentVariables 子元素For information on setting environment variables in web.config, see environmentVariables child element of aspNetCore.

從應用程式取得資料Obtain data from an app

若應用程式能夠回應要求、請使用終端機內嵌中介軟體從應用程式取得要求、連線與額外資料。If an app is capable of responding to requests, obtain request, connection, and additional data from the app using terminal inline middleware. 如如需詳細資訊與範例程式碼,請參閱 疑難排解 ASP.NET Core 專案For more information and sample code, see 疑難排解 ASP.NET Core 專案.

緩慢或懸掛應用程式 (IIS)Slow or hanging app (IIS)

傾印是系統記憶體的快照集, 有助於判斷應用程式損毀、啟動失敗或應用程式緩慢的原因。A crash dump is a snapshot of the system's memory and can help determine the cause of an app crash, startup failure, or slow app.

應用程式損毀或發生例外狀況App crashes or encounters an exception

Windows 錯誤報告 (WER) 取得並分析傾印:Obtain and analyze a dump from Windows Error Reporting (WER):

  1. c:\dumps 中建立資料夾以保存損毀傾印檔案。Create a folder to hold crash dump files at c:\dumps. 應用程式集區必須具備該資料夾的寫入權限。The app pool must have write access to the folder.

  2. 執行 EnableDumps PowerShell 指令碼Run the EnableDumps PowerShell script:

  3. 在會導致損毀的情況下,執行應用程式。Run the app under the conditions that cause the crash to occur.

  4. 發生損毀之後,請執行 DisableDumps PowerShell 指令碼After the crash has occurred, run the DisableDumps PowerShell script:

在應用程式損毀且傾印收集完成之後,即可正常結束應用程式。After an app crashes and dump collection is complete, the app is allowed to terminate normally. PowerShell 指令碼會將 WER 設定為每個應用程式收集最多五個傾印。The PowerShell script configures WER to collect up to five dumps per app.

警告

損毀傾印可能會佔用大量磁碟空間 (每個高達好幾 GB)。Crash dumps might take up a large amount of disk space (up to several gigabytes each).

應用程式停止回應、在啟動期間失敗,或正常執行App hangs, fails during startup, or runs normally

當應用程式「停止回應」(停止回應但未損毀)、在啟動期間失敗,或正常執行時,請參閱使用者模式傾印檔案:選擇最適合的工具,選取適當的工具來產生傾印。When an app hangs (stops responding but doesn't crash), fails during startup, or runs normally, see User-Mode Dump Files: Choosing the Best Tool to select an appropriate tool to produce the dump.

分析傾印Analyze the dump

您可以使用數種方法來分析傾印。A dump can be analyzed using several approaches. 如需詳細資訊,請參閱分析使用者模式傾印檔案For more information, see Analyzing a User-Mode Dump File.

清除套件快取Clear package caches

有時候, 正常運作的應用程式會在升級開發電腦上的 .NET Core SDK, 或變更應用程式內的套件版本之後立即失敗。Sometimes a functioning app fails immediately after upgrading either the .NET Core SDK on the development machine or changing package versions within the app. 在某些情況下,執行主要升級時,不一致的套件可能會中斷應用程式。In some cases, incoherent packages may break an app when performing major upgrades. 大多數這些問題都可依照下列指示來進行修正:Most of these issues can be fixed by following these instructions:

  1. 刪除 [bin] 和 [obj] 資料夾。Delete the bin and obj folders.

  2. 從命令 shell 執行dotnet nuget locals all --clear , 以清除套件快取。Clear the package caches by executing dotnet nuget locals all --clear from a command shell.

    清除套件快取也可以使用nuget.exe工具來完成, 並執行命令nuget locals all -clearClearing package caches can also be accomplished with the nuget.exe tool and executing the command nuget locals all -clear. nuget.exe 並未隨附在 Windows 桌面作業系統的安裝中,必須另外從 NuGet 網站取得。nuget.exe isn't a bundled install with the Windows desktop operating system and must be obtained separately from the NuGet website.

  3. 還原並重建專案。Restore and rebuild the project.

  4. 重新部署應用程式之前, 請先刪除伺服器上 [部署] 資料夾中的所有檔案。Delete all of the files in the deployment folder on the server prior to redeploying the app.

其他資源Additional resources

Azure 檔Azure documentation

Visual Studio 文件Visual Studio documentation

Visual Studio Code 檔Visual Studio Code documentation