diff --git a/aspnetcore/test/troubleshoot-azure-iis.md b/aspnetcore/test/troubleshoot-azure-iis.md index 2e641a9089c6..11ee40beccf2 100644 --- a/aspnetcore/test/troubleshoot-azure-iis.md +++ b/aspnetcore/test/troubleshoot-azure-iis.md @@ -12,7 +12,7 @@ uid: test/troubleshoot-azure-iis :::moniker range=">= aspnetcore-8.0" -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: +This article provides information on common app startup errors and instructions on how to diagnose errors when an app is deployed to IIS: [App startup errors](#app-startup-errors) Explains common startup HTTP status code scenarios. @@ -50,13 +50,12 @@ The error is usually caused by a broken deployment on the hosting system, which Perform the following steps: 1. Delete all of the files and folders from the deployment folder on the hosting system. -1. 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: - * Confirm that the *web.config* file is present in the deployment and that its contents are correct. - * When hosting on Azure App Service, confirm that the app is deployed to the `D:\home\site\wwwroot` folder. - * 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**. +1. 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. * Confirm that the: + *web.config* file is present in the deployment and that its contents are correct. + * App is deployed to the IIS **Physical path** shown in **IIS Manager**'s **Basic Settings**. 1. 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. -For more information on the layout of a published ASP.NET Core app, see . For more information on the *web.config* file, see . +For more information on the *web.config* file, see . ### 500 Internal Server Error @@ -82,10 +81,7 @@ The worker process fails. The app doesn't start. The [ASP.NET Core Module](xref:host-and-deploy/aspnet-core-module) attempts to start the .NET Core CLR in-process, but it fails to start. 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. -Common failure conditions: - -* The app is misconfigured due to targeting a version of the ASP.NET Core shared framework that isn't present. Check which versions of the ASP.NET Core shared framework are installed on the target machine. -* Using Azure Key Vault, lack of permissions to the Key Vault. Check the access policies in the targeted Key Vault to ensure that the correct permissions are granted. +The app my be misconfigured due to targeting a version of the ASP.NET Core shared framework that isn't present. Check which versions of the ASP.NET Core shared framework are installed on the target machine. ### 500.31 ANCM Failed to Find Native Dependencies @@ -115,7 +111,7 @@ When running in development (the `ASPNETCORE_ENVIRONMENT` environment variable i 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. If the worker process is running as a 32-bit app and the app was published to target 64-bit, this error occurs. +Typically, the app is published for an incompatible processor architecture. 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: @@ -212,7 +208,7 @@ The following command enables the `null` Windows Service: sc.exe start null ``` -### Connection reset +### IIS Connection reset 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](xref:fundamentals/logging/index) can help troubleshoot these types of errors. @@ -220,129 +216,339 @@ If an error occurs after the headers are sent, it's too late for the server to s The [ASP.NET Core Module](xref:host-and-deploy/aspnet-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. For information on configuring the module, see [Attributes of the aspNetCore element](xref:host-and-deploy/aspnet-core-module#attributes-of-the-aspnetcore-element). -## Troubleshoot on Azure App Service +### ASP.NET Core Module stdout log (Azure App Service) -[!INCLUDE [Azure App Service Preview Notice](~/includes/azure-apps-preview-notice.md)] +> [!WARNING] +> 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. Only use stdout logging to troubleshoot app startup problems. +> +> 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](xref:fundamentals/logging/index#third-party-logging-providers). -### Azure App Services Log stream +#### Kudu console -The Azure App Services Log streams logging information as it occurs. To view streaming logs: +Navigate to the Kudu console to enable stdout logging: +1. In the Azure Portal, navigate to the web app. +1. In the **App Service** blade, enter **kudu** in the search box. +1. Select **Advanced Tools** > **Go**. +1. Select **Debug console > CMD**. +1. Navigate to *site/wwwroot* +1. Select the pencil icon to edit the *web.config* file. +1. In the `` element, set `stdoutLogEnabled="true"` and select **Save**. -1. In the Azure portal, open the app in **App Services**. -1. In the left pane, navigate to **Monitoring** > **App Service Logs**. - ![App Service Logs](https://user-images.githubusercontent.com/3605364/183573538-80645002-d1c3-4451-9a2f-91ef4de4e248.png) -1. Select **File System** for **Web Server Logging**. Optionally enable **Application logging**. - ![enable logging](https://user-images.githubusercontent.com/3605364/183529287-f63d3e1c-ee5b-4ca1-bcb6-a8c29d8b26f5.png) -1. In the left pane, navigate to **Monitoring** > **Log stream**, and then select **Application logs** or **Web Server Logs**. +Disable stdout logging when troubleshooting is complete by setting `stdoutLogEnabled="false"`. - ![Monitoring Log stream](https://user-images.githubusercontent.com/3605364/183561255-91f3d5e1-141b-413b-a403-91e74a770545.png) +For more information, see . + + - The following images shows the application logs output: +### ASP.NET Core Module debug log (Azure App Service) - ![app logs](https://user-images.githubusercontent.com/3605364/183528795-532665c0-ce87-4ed3-8e4d-4b374d469c2a.png) +The ASP.NET Core Module debug log provides additional, deeper logging from the ASP.NET Core Module. To enable and view stdout logs: -Streaming logs have some latency and might not display immediately. +1. To enable the enhanced diagnostic log, perform either of the following: + * Follow the instructions in [Enhanced diagnostic logs](xref:host-and-deploy/iis/logging-and-diagnostics#enhanced-diagnostic-logs) to configure the app for an enhanced diagnostic logging. Redeploy the app. + * Add the `` shown in [Enhanced diagnostic logs](xref:host-and-deploy/iis/logging-and-diagnostics#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. The Kudu console opens in a new browser tab or window. + 1. Using the navigation bar at the top of the page, open **Debug console** and select **CMD**. + 1. Open the folders to the path **site** > **wwwroot**. Edit the *web.config* file by selecting the pencil button. Add the `` section as shown in [Enhanced diagnostic logs](xref:host-and-deploy/iis/logging-and-diagnostics#enhanced-diagnostic-logs). Select the **Save** button. +1. Open **Advanced Tools** in the **Development Tools** area. Select the **Go→** button. The Kudu console opens in a new browser tab or window. +1. Using the navigation bar at the top of the page, open **Debug console** and select **CMD**. +1. Open the folders to the path **site** > **wwwroot**. 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. +1. Open the log file with the pencil button next to the file name. -### Application Event Log (Azure App Service) +Disable debug logging when troubleshooting is complete: -To access the Application Event Log, use the **Diagnose and solve problems** blade in the Azure portal: +To disable the enhanced debug log, perform either of the following: -1. In the Azure portal, open the app in **App Services**. -1. Select **Diagnose and solve problems**. -1. Select the **Diagnostic Tools** heading. -1. Under **Support Tools**, select the **Application Events** button. -1. Examine the latest error provided by the *IIS AspNetCoreModule* or *IIS AspNetCoreModule V2* entry in the **Source** column. +* Remove the `` from the *web.config* file locally and redeploy the app. +* Use the Kudu console to edit the *web.config* file and remove the `` section. Save the file. -An alternative to using the **Diagnose and solve problems** blade is to examine the Application Event Log file directly using [Kudu](https://github.com/projectkudu/kudu/wiki): +For more information, see . -1. Open **Advanced Tools** in the **Development Tools** area. Select the **Go→** button. The Kudu console opens in a new browser tab or window. -1. Using the navigation bar at the top of the page, open **Debug console** and select **CMD**. -1. Open the **LogFiles** folder. -1. Select the pencil icon next to the `eventlog.xml` file. -1. Examine the log. Scroll to the bottom of the log to see the most recent events. +> [!WARNING] +> 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. +> +> 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](xref:fundamentals/logging/index#third-party-logging-providers). + +### Slow or hanging app (Azure App Service) -### Run the app in the Kudu console +When an app responds slowly or hangs on a request, see [Troubleshoot slow web app performance issues in Azure App Service](/azure/app-service/app-service-web-troubleshoot-performance-degradation). -Many startup errors don't produce useful information in the Application Event Log. You can run the app in the [Kudu](https://github.com/projectkudu/kudu/wiki) Remote Execution Console to discover the error: +### Monitoring blades -1. Open **Advanced Tools** in the **Development Tools** area. Select the **Go→** button. The Kudu console opens in a new browser tab or window. +Monitoring blades provide an alternative troubleshooting experience to the methods described earlier in the topic. These blades can be used to diagnose 500-series errors. + +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. +1. The **ASP.NET Core Extensions** should appear in the list. +1. If the extensions aren't installed, select the **Add** button. +1. Choose the **ASP.NET Core Extensions** from the list. +1. Select **OK** to accept the legal terms. +1. Select **OK** on the **Add extension** blade. +1. An informational pop-up message indicates when the extensions are successfully installed. + +If stdout logging isn't enabled, follow these steps: + +1. In the Azure portal, select the **Advanced Tools** blade in the **DEVELOPMENT TOOLS** area. Select the **Go→** button. The Kudu console opens in a new browser tab or window. 1. Using the navigation bar at the top of the page, open **Debug console** and select **CMD**. +1. Open the folders to the path **site** > **wwwroot** and scroll down to reveal the *web.config* file at the bottom of the list. +1. Click the pencil icon next to the *web.config* file. +1. Set **stdoutLogEnabled** to `true` and change the **stdoutLogFile** path to: `\\?\%home%\LogFiles\stdout`. +1. Select **Save** to save the updated *web.config* file. -#### Test a 32-bit (x86) app +Proceed to activate diagnostic logging: -**Current release** +1. In the Azure portal, select the **Diagnostics logs** blade. +1. Select the **On** switch for **Application Logging (Filesystem)** and **Detailed error messages**. Select the **Save** button at the top of the blade. +1. To include failed request tracing, also known as Failed Request Event Buffering (FREB) logging, select the **On** switch for **Failed request tracing**. +1. Select the **Log stream** blade, which is listed immediately under the **Diagnostics logs** blade in the portal. +1. Make a request to the app. +1. Within the log stream data, the cause of the error is indicated. -1. `cd d:\home\site\wwwroot` -1. Run the app: - * If the app is a [framework-dependent deployment](/dotnet/core/deploying/#framework-dependent-deployments-fdd): +Be sure to disable stdout logging when troubleshooting is complete. + +To view the failed request tracing logs (FREB logs): - ```dotnetcli - dotnet .\{ASSEMBLY NAME}.dll +1. Navigate to the **Diagnose and solve problems** blade in the Azure portal. +1. Select **Failed Request Tracing Logs** from the **SUPPORT TOOLS** area of the sidebar. + +See [Failed request traces section of the Enable diagnostics logging for web apps in Azure App Service topic](/azure/app-service/web-sites-enable-diagnostic-log#failed-request-traces) and the [Application performance FAQs for Web Apps in Azure: How do I turn on failed request tracing?](/azure/app-service/app-service-web-availability-performance-application-issues-faq#how-do-i-turn-on-failed-request-tracing) for more information. + +For more information, see [Enable diagnostics logging for web apps in Azure App Service](/azure/app-service/web-sites-enable-diagnostic-log). + +> [!WARNING] +> 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. +> +> 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](xref:fundamentals/logging/index#third-party-logging-providers). + +## Troubleshoot on IIS + +### Application Event Log (IIS) + +Access the Application Event Log: + +1. Open the Start menu, search for *Event Viewer*, and select the **Event Viewer** app. +1. In **Event Viewer**, open the **Windows Logs** node. +1. Select **Application** to open the Application Event Log. +1. Search for errors associated with the failing app. Errors 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-dependent deployment + +If the app is a [framework-dependent deployment](/dotnet/core/deploying/#framework-dependent-deployments-fdd): + +1. At a command prompt, navigate to the deployment folder and run the app by executing the app's assembly with *dotnet.exe*. In the following command, substitute the name of the app's assembly for \: `dotnet .\.dll`. +1. The console output from the app, showing any errors, is written to the console window. +1. If the errors occur when making a request to the app, make a request to the host and port where Kestrel listens. Using the default host and post, make a request to `http://localhost:5000/`. 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](/dotnet/core/deploying/#self-contained-deployments-scd): + +1. At a command prompt, navigate to the deployment folder and run the app's executable. In the following command, substitute the name of the app's assembly for \: `.exe`. +1. The console output from the app, showing any errors, is written to the console window. +1. If the errors occur when making a request to the app, make a request to the host and port where Kestrel listens. Using the default host and post, make a request to `http://localhost:5000/`. 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 Module stdout log (IIS) + +To enable and view stdout logs: + +1. Navigate to the site's deployment folder on the hosting system. +1. If the *logs* folder isn't present, create the folder. For instructions on how to enable MSBuild to create the *logs* folder in the deployment automatically, see the [Directory structure](xref:host-and-deploy/directory-structure) topic. +1. Edit the *web.config* file. Set **stdoutLogEnabled** to `true` and change the **stdoutLogFile** path to point to the *logs* folder (for example, `.\logs\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. Using `stdout` as the file name prefix, a typical log file is named *stdout_20180205184032_5412.log*. +1. Ensure your application pool's identity has write permissions to the *logs* folder. +1. Save the updated *web.config* file. +1. Make a request to the app. +1. Navigate to the *logs* folder. Find and open the most recent stdout log. +1. Study the log for errors. + +Disable stdout logging when troubleshooting is complete: + +1. Edit the *web.config* file. +1. Set **stdoutLogEnabled** to `false`. +1. Save the file. + +For more information, see . + +> [!WARNING] +> 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. +> +> 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](xref:fundamentals/logging/index#third-party-logging-providers). + +### ASP.NET Core Module debug log (IIS) + +Add the following handler settings to the app's *web.config* file to enable ASP.NET Core Module debug log: + +```xml + + + + + + +``` + +Confirm that the path specified for the log exists and that the app pool's identity has write permissions to the location. + +For more information, see . + +### Enable the Developer Exception Page + +The `ASPNETCORE_ENVIRONMENT` [environment variable can be added to web.config](xref:host-and-deploy/aspnet-core-module#setting-environment-variables) to run the app in the Development environment. 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](xref:fundamentals/error-handling) to appear when the app is run. + +```xml + + + + + +``` + +Setting the environment variable for `ASPNETCORE_ENVIRONMENT` is only recommended for use on staging and testing servers that aren't exposed to the Internet. Remove the environment variable from the *web.config* file after troubleshooting. For information on setting environment variables in *web.config*, see [environmentVariables child element of aspNetCore](xref:host-and-deploy/aspnet-core-module#setting-environment-variables). + +### 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. For more information and sample code, see . + +### 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 + +Obtain and analyze a dump from [Windows Error Reporting (WER)](/windows/desktop/wer/windows-error-reporting): + +1. Create a folder to hold crash dump files at `c:\dumps`. The app pool must have write access to the folder. +1. Run the [EnableDumps PowerShell script](https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/test/troubleshoot-azure-iis/scripts/EnableDumps.ps1): + * If the app uses the [in-process hosting model](xref:host-and-deploy/iis/index#in-process-hosting-model), run the script for *w3wp.exe*: + + ```console + .\EnableDumps w3wp.exe c:\dumps ``` - * If the app is a [self-contained deployment](/dotnet/core/deploying/#self-contained-deployments-scd): + * If the app uses the [out-of-process hosting model](xref:host-and-deploy/iis/index#out-of-process-hosting-model), run the script for *dotnet.exe*: ```console - {ASSEMBLY NAME}.exe + .\EnableDumps dotnet.exe c:\dumps ``` -The console output from the app, showing any errors, is piped to the Kudu console. +1. Run the app under the conditions that cause the crash to occur. +1. After the crash has occurred, run the [DisableDumps PowerShell script](https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/test/troubleshoot-azure-iis/scripts/DisableDumps.ps1): + * If the app uses the [in-process hosting model](xref:host-and-deploy/iis/index#in-process-hosting-model), run the script for *w3wp.exe*: -**Framework-dependent deployment running on a preview release** + ```console + .\DisableDumps w3wp.exe + ``` -*Requires installing the ASP.NET Core {VERSION} (x86) Runtime site extension.* + * If the app uses the [out-of-process hosting model](xref:host-and-deploy/iis/index#out-of-process-hosting-model), run the script for *dotnet.exe*: -1. `cd D:\home\SiteExtensions\AspNetCoreRuntime.{X.Y}.x32` (`{X.Y}` is the runtime version) -1. Run the app: `dotnet \home\site\wwwroot\{ASSEMBLY NAME}.dll` + ```console + .\DisableDumps dotnet.exe + ``` -The console output from the app, showing any errors, is piped to the Kudu console. +After an app crashes and dump collection is complete, the app is allowed to terminate normally. The PowerShell script configures WER to collect up to five dumps per app. -#### Test a 64-bit (x64) app +> [!WARNING] +> Crash dumps might take up a large amount of disk space (up to several gigabytes each). -**Current release** +#### App hangs, fails during startup, or runs normally -* If the app is a 64-bit (x64) [framework-dependent deployment](/dotnet/core/deploying/#framework-dependent-deployments-fdd): - 1. `cd D:\Program Files\dotnet` - 1. Run the app: `dotnet \home\site\wwwroot\{ASSEMBLY NAME}.dll` -* If the app is a [self-contained deployment](/dotnet/core/deploying/#self-contained-deployments-scd): - 1. `cd D:\home\site\wwwroot` - 1. Run the app: `{ASSEMBLY NAME}.exe` +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](/windows-hardware/drivers/debugger/user-mode-dump-files#choosing-the-best-tool) to select an appropriate tool to produce the dump. -The console output from the app, showing any errors, is piped to the Kudu console. +#### Analyze the dump -**Framework-dependent deployment running on a preview release** +A dump can be analyzed using several approaches. For more information, see [Analyzing a User-Mode Dump File](/windows-hardware/drivers/debugger/analyzing-a-user-mode-dump-file). -*Requires installing the ASP.NET Core {VERSION} (x64) Runtime site extension.* +## Clear package caches -1. `cd D:\home\SiteExtensions\AspNetCoreRuntime.{X.Y}.x64` (`{X.Y}` is the runtime version) -1. Run the app: `dotnet \home\site\wwwroot\{ASSEMBLY NAME}.dll` +A functioning app may fail 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: -The console output from the app, showing any errors, is piped to the Kudu console. +1. Delete the *bin* and *obj* folders. +1. Clear the package caches by executing [dotnet nuget locals all --clear](/dotnet/core/tools/dotnet-nuget-locals) from a command shell. -### ASP.NET Core Module stdout log (Azure App Service) + Clearing package caches can also be accomplished with the [nuget.exe](https://www.nuget.org/downloads) tool and executing the command `nuget locals all -clear`. *nuget.exe* isn't a bundled install with the Windows desktop operating system and must be obtained separately from the [NuGet website](https://www.nuget.org/downloads). -> [!WARNING] -> 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. Only use stdout logging to troubleshoot app startup problems. -> -> 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](xref:fundamentals/logging/index#third-party-logging-providers). +1. Restore and rebuild the project. +1. Delete all of the files in the deployment folder on the server prior to redeploying the app. -The ASP.NET Core Module stdout log often records useful error messages not found in the Application Event Log. To enable and view stdout logs: +## Additional resources -1. In the Azure Portal, navigate to the web app. -1. In the **App Service** blade, enter **kudu** in the search box. -1. Select **Advanced Tools** > **Go**. -1. Select **Debug console > CMD**. -1. Navigate to *site/wwwroot* -1. Select the pencil icon to edit the *web.config* file. -1. In the `` element, set `stdoutLogEnabled="true"` and select **Save**. +* +* +* +* +* -Disable stdout logging when troubleshooting is complete by setting `stdoutLogEnabled="false"`. +### Azure documentation -For more information, see . +* [Application Insights for ASP.NET Core](/azure/application-insights/app-insights-asp-net-core) +* [Remote debugging web apps section of Troubleshoot a web app in Azure App Service using Visual Studio](/azure/app-service/web-sites-dotnet-troubleshoot-visual-studio#remotedebug) +* [Azure App Service diagnostics overview](/azure/app-service/app-service-diagnostics) +* [How to: Monitor Apps in Azure App Service](/azure/app-service/web-sites-monitor) +* [Troubleshoot a web app in Azure App Service using Visual Studio](/azure/app-service/web-sites-dotnet-troubleshoot-visual-studio) +* [Troubleshoot HTTP errors of "502 bad gateway" and "503 service unavailable" in your Azure web apps](/azure/app-service/app-service-web-troubleshoot-http-502-http-503) +* [Troubleshoot slow web app performance issues in Azure App Service](/azure/app-service/app-service-web-troubleshoot-performance-degradation) +* [Application performance FAQs for Web Apps in Azure](/azure/app-service/app-service-web-availability-performance-application-issues-faq) +* [Azure Web App sandbox (App Service runtime execution limitations)](https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox) - +### Visual Studio documentation -### ASP.NET Core Module debug log (Azure App Service) +* [Remote Debug ASP.NET Core on IIS in Azure in Visual Studio 2017](/visualstudio/debugger/remote-debugging-azure) +* [Remote Debug ASP.NET Core on a Remote IIS Computer in Visual Studio 2017](/visualstudio/debugger/remote-debugging-aspnet-on-a-remote-iis-computer) +* [Learn to debug using Visual Studio](/visualstudio/debugger/getting-started-with-the-debugger) + +### Visual Studio Code documentation + +* [Debugging with Visual Studio Code](https://code.visualstudio.com/docs/editor/debugging) + +## Troubleshoot ASP.NET Core on Azure App Service + +This article provides information on how to diagnose problems and errors when an app is deployed to [Azure App Service](/azure/app-service/). + +[!INCLUDE [Azure App Service Preview Notice](~/includes/azure-apps-preview-notice.md)] + +If the problem can be reproduced locally, the Visual Studio debugger is a good choice. See [Visual Troubleshoot an app in Azure App Service using Visual Studio](/visualstudio/debugger/remote-debugging-azure) to troubleshoot on Azure. + +The following tools can be used to diagnose problems: + + +* Azure App Services stream diagnostics logs, see [Enable diagnostics logging for apps in Azure App Service](/azure/app-service/web-sites-enable-diagnostic-log). The following list shows how to enable logging for different categories: + * [ASP.NET Core categories](/aspnet/core/fundamentals/logging#aspnet-core-categories) + * + * + * + Streaming logs have latency and typically take many seconds to appear. +* Application Event Logs: + 1. Navigate to the **App Service** blade in the Azure portal. + 1. Select **Diagnose and solve problems**. + 1. In the **Diagnostic Tools** tile, select **Application Event Logs**. +* Kudu console: See the [Kudu wiki](https://github.com/projectkudu/kudu/wiki) and [Kudu service overview](/azure/app-service/resources-kudu). The Kudo wiki provides information on how to download logs. +* Availability and Performance: The [Availability and Performance](/azure/app-service/overview-diagnostics#troubleshooting-categories) tile in [Diagnose and solve problems](/azure/app-service/overview-diagnostics) +* When an app responds slowly or hangs on a request, see [Troubleshoot slow web app performance issues in Azure App Service](/azure/app-service/app-service-web-troubleshoot-performance-degradation). + +Many startup errors don't produce useful information in the Application Event Log. Runing the app in the [Kudu](https://github.com/projectkudu/kudu/wiki) Remote Execution Console often provides error information + +## Connection reset + +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](xref:fundamentals/logging/index) can help troubleshoot these types of errors. + +#### 32-bit and 64-bit mismatch + +In the Azure Portal, navigate to the App Service and check **Settings > Configuration > Platform settings**. Ensure that the platform architecture matches the architecture of the app deployment (32-bit or 64-bit). + +![Platform settings image](https://github.com/user-attachments/assets/ad0673a4-57df-4cd4-87c2-d178c9792497) The ASP.NET Core Module debug log provides additional, deeper logging from the ASP.NET Core Module. To enable and view stdout logs: @@ -371,11 +577,9 @@ For more information, see > 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](xref:fundamentals/logging/index#third-party-logging-providers). -### Slow or hanging app (Azure App Service) -When an app responds slowly or hangs on a request, see [Troubleshoot slow web app performance issues in Azure App Service](/azure/app-service/app-service-web-troubleshoot-performance-degradation). -### Monitoring blades +### z Monitoring blades Monitoring blades provide an alternative troubleshooting experience to the methods described earlier in the topic. These blades can be used to diagnose 500-series errors. @@ -423,9 +627,9 @@ For more information, see [Enable diagnostics logging for web apps in Azure App > > 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](xref:fundamentals/logging/index#third-party-logging-providers). -## Troubleshoot on IIS +## z Troubleshoot on IIS -### Application Event Log (IIS) +### z Application Event Log (IIS) Access the Application Event Log: @@ -434,11 +638,11 @@ Access the Application Event Log: 1. Select **Application** to open the Application Event Log. 1. Search for errors associated with the failing app. Errors have a value of *IIS AspNetCore Module* or *IIS Express AspNetCore Module* in the *Source* column. -### Run the app at a command prompt +### z 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-dependent deployment +#### z Framework-dependent deployment If the app is a [framework-dependent deployment](/dotnet/core/deploying/#framework-dependent-deployments-fdd): @@ -446,7 +650,7 @@ If the app is a [framework-dependent deployment](/dotnet/core/deploying/#framewo 1. The console output from the app, showing any errors, is written to the console window. 1. If the errors occur when making a request to the app, make a request to the host and port where Kestrel listens. Using the default host and post, make a request to `http://localhost:5000/`. 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 +#### z Self-contained deployment If the app is a [self-contained deployment](/dotnet/core/deploying/#self-contained-deployments-scd): @@ -454,7 +658,7 @@ If the app is a [self-contained deployment](/dotnet/core/deploying/#self-contain 1. The console output from the app, showing any errors, is written to the console window. 1. If the errors occur when making a request to the app, make a request to the host and port where Kestrel listens. Using the default host and post, make a request to `http://localhost:5000/`. 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 Module stdout log (IIS) +### z ASP.NET Core Module stdout log (IIS) To enable and view stdout logs: @@ -480,7 +684,7 @@ For more information, see > 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](xref:fundamentals/logging/index#third-party-logging-providers). -### ASP.NET Core Module debug log (IIS) +### z ASP.NET Core Module debug log (IIS) Add the following handler settings to the app's *web.config* file to enable ASP.NET Core Module debug log: @@ -497,7 +701,7 @@ Confirm that the path specified for the log exists and that the app pool's ident For more information, see . -### Enable the Developer Exception Page +### z Enable the Developer Exception Page The `ASPNETCORE_ENVIRONMENT` [environment variable can be added to web.config](xref:host-and-deploy/aspnet-core-module#setting-environment-variables) to run the app in the Development environment. 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](xref:fundamentals/error-handling) to appear when the app is run. @@ -515,15 +719,15 @@ The `ASPNETCORE_ENVIRONMENT` [environment variable can be added to web.config](x Setting the environment variable for `ASPNETCORE_ENVIRONMENT` is only recommended for use on staging and testing servers that aren't exposed to the Internet. Remove the environment variable from the *web.config* file after troubleshooting. For information on setting environment variables in *web.config*, see [environmentVariables child element of aspNetCore](xref:host-and-deploy/aspnet-core-module#setting-environment-variables). -### Obtain data from an app +### z 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. For more information and sample code, see . -### Slow or hanging app (IIS) +### z 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 +#### z App crashes or encounters an exception Obtain and analyze a dump from [Windows Error Reporting (WER)](/windows/desktop/wer/windows-error-reporting): @@ -560,15 +764,15 @@ After an app crashes and dump collection is complete, the app is allowed to term > [!WARNING] > Crash dumps might take up a large amount of disk space (up to several gigabytes each). -#### App hangs, fails during startup, or runs normally +#### z 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](/windows-hardware/drivers/debugger/user-mode-dump-files#choosing-the-best-tool) to select an appropriate tool to produce the dump. -#### Analyze the dump +#### z Analyze the dump A dump can be analyzed using several approaches. For more information, see [Analyzing a User-Mode Dump File](/windows-hardware/drivers/debugger/analyzing-a-user-mode-dump-file). -## Clear package caches +## z Clear package caches A functioning app may fail 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: @@ -580,7 +784,7 @@ A functioning app may fail immediately after upgrading either the .NET Core SDK 1. Restore and rebuild the project. 1. Delete all of the files in the deployment folder on the server prior to redeploying the app. -## Additional resources +## z Additional resources * * @@ -588,7 +792,7 @@ A functioning app may fail immediately after upgrading either the .NET Core SDK * * -### Azure documentation +### z Azure documentation * [Application Insights for ASP.NET Core](/azure/application-insights/app-insights-asp-net-core) * [Remote debugging web apps section of Troubleshoot a web app in Azure App Service using Visual Studio](/azure/app-service/web-sites-dotnet-troubleshoot-visual-studio#remotedebug) @@ -600,7 +804,7 @@ A functioning app may fail immediately after upgrading either the .NET Core SDK * [Application performance FAQs for Web Apps in Azure](/azure/app-service/app-service-web-availability-performance-application-issues-faq) * [Azure Web App sandbox (App Service runtime execution limitations)](https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox) -### Visual Studio documentation +### z Visual Studio documentation * [Remote Debug ASP.NET Core on IIS in Azure in Visual Studio 2017](/visualstudio/debugger/remote-debugging-azure) * [Remote Debug ASP.NET Core on a Remote IIS Computer in Visual Studio 2017](/visualstudio/debugger/remote-debugging-aspnet-on-a-remote-iis-computer) @@ -612,5 +816,7 @@ A functioning app may fail immediately after upgrading either the .NET Core SDK :::moniker-end + + [!INCLUDE[](~/test/troubleshoot-azure-iis/includes/troubleshoot-azure-iis2.md)] [!INCLUDE[](~/test/troubleshoot-azure-iis/includes/troubleshoot-azure-iis7.md)]