|
| 1 | +:::moniker range="< aspnetcore-6.0" |
| 2 | + |
| 3 | +By [Rick Anderson](https://twitter.com/RickAndMSFT) |
| 4 | + |
| 5 | +The following links provide troubleshooting guidance: |
| 6 | + |
| 7 | +* <xref:test/troubleshoot-azure-iis> |
| 8 | +* <xref:host-and-deploy/azure-iis-errors-reference> |
| 9 | +* [NDC Conference (London, 2018): Diagnosing issues in ASP.NET Core Applications](https://www.youtube.com/watch?v=RYI0DHoIVaA) |
| 10 | +* [ASP.NET Blog: Troubleshooting ASP.NET Core Performance Problems](https://blogs.msdn.microsoft.com/webdev/2018/05/23/asp-net-core-performance-improvements/) |
| 11 | + |
| 12 | +## .NET Core SDK warnings |
| 13 | + |
| 14 | +### Both the 32-bit and 64-bit versions of the .NET Core SDK are installed |
| 15 | + |
| 16 | +In the **New Project** dialog for ASP.NET Core, you may see the following warning: |
| 17 | + |
| 18 | +> Both 32-bit and 64-bit versions of the .NET Core SDK are installed. Only templates from the 64-bit versions installed at 'C:\\Program Files\\dotnet\\sdk\\' are displayed. |
| 19 | +
|
| 20 | +This warning appears when both 32-bit (x86) and 64-bit (x64) versions of the [.NET Core SDK](https://dotnet.microsoft.com/download/dotnet-core) are installed. Common reasons both versions may be installed include: |
| 21 | + |
| 22 | +* You originally downloaded the .NET Core SDK installer using a 32-bit machine but then copied it across and installed it on a 64-bit machine. |
| 23 | +* The 32-bit .NET Core SDK was installed by another application. |
| 24 | +* The wrong version was downloaded and installed. |
| 25 | + |
| 26 | +Uninstall the 32-bit .NET Core SDK to prevent this warning. Uninstall from **Control Panel** > **Programs and Features** > **Uninstall or change a program**. If you understand why the warning occurs and its implications, you can ignore the warning. |
| 27 | + |
| 28 | +### The .NET Core SDK is installed in multiple locations |
| 29 | + |
| 30 | +In the **New Project** dialog for ASP.NET Core, you may see the following warning: |
| 31 | + |
| 32 | +> The .NET Core SDK is installed in multiple locations. Only templates from the SDKs installed at 'C:\\Program Files\\dotnet\\sdk\\' are displayed. |
| 33 | +
|
| 34 | +You see this message when you have at least one installation of the .NET Core SDK in a directory outside of *C:\\Program Files\\dotnet\\sdk\\*. Usually this happens when the .NET Core SDK has been deployed on a machine using copy/paste instead of the MSI installer. |
| 35 | + |
| 36 | +Uninstall all 32-bit .NET Core SDKs and runtimes to prevent this warning. Uninstall from **Control Panel** > **Programs and Features** > **Uninstall or change a program**. If you understand why the warning occurs and its implications, you can ignore the warning. |
| 37 | + |
| 38 | +### No .NET Core SDKs were detected |
| 39 | + |
| 40 | +* In the Visual Studio **New Project** dialog for ASP.NET Core, you may see the following warning: |
| 41 | + |
| 42 | + > No .NET Core SDKs were detected, ensure they are included in the environment variable `PATH`. |
| 43 | +
|
| 44 | +* When executing a `dotnet` command, the warning appears as: |
| 45 | + |
| 46 | + > It was not possible to find any installed dotnet SDKs. |
| 47 | +
|
| 48 | +These warnings appear when the environment variable `PATH` doesn't point to any .NET Core SDKs on the machine. To resolve this problem: |
| 49 | + |
| 50 | +* Install the .NET Core SDK. Obtain the latest installer from [.NET Downloads](https://dotnet.microsoft.com/download). |
| 51 | +* Verify that the `PATH` environment variable points to the location where the SDK is installed (`C:\Program Files\dotnet\` for 64-bit/x64 or `C:\Program Files (x86)\dotnet\` for 32-bit/x86). The SDK installer normally sets the `PATH`. Always install the same bitness SDKs and runtimes on the same machine. |
| 52 | + |
| 53 | +### Missing SDK after installing the .NET Core Hosting Bundle |
| 54 | + |
| 55 | +Installing the [.NET Core Hosting Bundle](xref:host-and-deploy/iis/index#install-the-net-core-hosting-bundle) modifies the `PATH` when it installs the .NET Core runtime to point to the 32-bit (x86) version of .NET Core (`C:\Program Files (x86)\dotnet\`). This can result in missing SDKs when the 32-bit (x86) .NET Core `dotnet` command is used ([No .NET Core SDKs were detected](#no-net-core-sdks-were-detected)). To resolve this problem, move `C:\Program Files\dotnet\` to a position before `C:\Program Files (x86)\dotnet\` on the `PATH`. |
| 56 | + |
| 57 | +## Obtain data from an app |
| 58 | + |
| 59 | +If an app is capable of responding to requests, you can obtain the following data from the app using middleware: |
| 60 | + |
| 61 | +* Request: Method, scheme, host, pathbase, path, query string, headers |
| 62 | +* Connection: Remote IP address, remote port, local IP address, local port, client certificate |
| 63 | +* Identity: Name, display name |
| 64 | +* Configuration settings |
| 65 | +* Environment variables |
| 66 | + |
| 67 | +Place the following [middleware](xref:fundamentals/middleware/index#create-a-middleware-pipeline-with-iapplicationbuilder) code at the beginning of the `Startup.Configure` method's request processing pipeline. The environment is checked before the middleware is run to ensure that the code is only executed in the Development environment. |
| 68 | + |
| 69 | +To obtain the environment, use either of the following approaches: |
| 70 | + |
| 71 | +* Inject the `IHostingEnvironment` into the `Startup.Configure` method and check the environment with the local variable. The following sample code demonstrates this approach. |
| 72 | + |
| 73 | +* Assign the environment to a property in the `Startup` class. Check the environment using the property (for example, `if (Environment.IsDevelopment())`). |
| 74 | + |
| 75 | +```csharp |
| 76 | +public void Configure(IApplicationBuilder app, IHostingEnvironment env, |
| 77 | + IConfiguration config) |
| 78 | +{ |
| 79 | + if (env.IsDevelopment()) |
| 80 | + { |
| 81 | + app.Run(async (context) => |
| 82 | + { |
| 83 | + var sb = new StringBuilder(); |
| 84 | + var nl = System.Environment.NewLine; |
| 85 | + var rule = string.Concat(nl, new string('-', 40), nl); |
| 86 | + var authSchemeProvider = app.ApplicationServices |
| 87 | + .GetRequiredService<IAuthenticationSchemeProvider>(); |
| 88 | + |
| 89 | + sb.Append($"Request{rule}"); |
| 90 | + sb.Append($"{DateTimeOffset.Now}{nl}"); |
| 91 | + sb.Append($"{context.Request.Method} {context.Request.Path}{nl}"); |
| 92 | + sb.Append($"Scheme: {context.Request.Scheme}{nl}"); |
| 93 | + sb.Append($"Host: {context.Request.Headers["Host"]}{nl}"); |
| 94 | + sb.Append($"PathBase: {context.Request.PathBase.Value}{nl}"); |
| 95 | + sb.Append($"Path: {context.Request.Path.Value}{nl}"); |
| 96 | + sb.Append($"Query: {context.Request.QueryString.Value}{nl}{nl}"); |
| 97 | + |
| 98 | + sb.Append($"Connection{rule}"); |
| 99 | + sb.Append($"RemoteIp: {context.Connection.RemoteIpAddress}{nl}"); |
| 100 | + sb.Append($"RemotePort: {context.Connection.RemotePort}{nl}"); |
| 101 | + sb.Append($"LocalIp: {context.Connection.LocalIpAddress}{nl}"); |
| 102 | + sb.Append($"LocalPort: {context.Connection.LocalPort}{nl}"); |
| 103 | + sb.Append($"ClientCert: {context.Connection.ClientCertificate}{nl}{nl}"); |
| 104 | + |
| 105 | + sb.Append($"Identity{rule}"); |
| 106 | + sb.Append($"User: {context.User.Identity.Name}{nl}"); |
| 107 | + var scheme = await authSchemeProvider |
| 108 | + .GetSchemeAsync(IISDefaults.AuthenticationScheme); |
| 109 | + sb.Append($"DisplayName: {scheme?.DisplayName}{nl}{nl}"); |
| 110 | + |
| 111 | + sb.Append($"Headers{rule}"); |
| 112 | + foreach (var header in context.Request.Headers) |
| 113 | + { |
| 114 | + sb.Append($"{header.Key}: {header.Value}{nl}"); |
| 115 | + } |
| 116 | + sb.Append(nl); |
| 117 | + |
| 118 | + sb.Append($"WebSockets{rule}"); |
| 119 | + if (context.Features.Get<IHttpUpgradeFeature>() != null) |
| 120 | + { |
| 121 | + sb.Append($"Status: Enabled{nl}{nl}"); |
| 122 | + } |
| 123 | + else |
| 124 | + { |
| 125 | + sb.Append($"Status: Disabled{nl}{nl}"); |
| 126 | + } |
| 127 | + |
| 128 | + sb.Append($"Configuration{rule}"); |
| 129 | + foreach (var pair in config.AsEnumerable()) |
| 130 | + { |
| 131 | + sb.Append($"{pair.Path}: {pair.Value}{nl}"); |
| 132 | + } |
| 133 | + sb.Append(nl); |
| 134 | + |
| 135 | + sb.Append($"Environment Variables{rule}"); |
| 136 | + var vars = System.Environment.GetEnvironmentVariables(); |
| 137 | + foreach (var key in vars.Keys.Cast<string>().OrderBy(key => key, |
| 138 | + StringComparer.OrdinalIgnoreCase)) |
| 139 | + { |
| 140 | + var value = vars[key]; |
| 141 | + sb.Append($"{key}: {value}{nl}"); |
| 142 | + } |
| 143 | + |
| 144 | + context.Response.ContentType = "text/plain"; |
| 145 | + await context.Response.WriteAsync(sb.ToString()); |
| 146 | + }); |
| 147 | + } |
| 148 | +} |
| 149 | +``` |
| 150 | + |
| 151 | +## Debug ASP.NET Core apps |
| 152 | + |
| 153 | +The following links provide information on debugging ASP.NET Core apps. |
| 154 | + |
| 155 | +* [Debugging ASP Core on Linux](https://devblogs.microsoft.com/premier-developer/debugging-asp-core-on-linux-with-visual-studio-2017/) |
| 156 | +* [Debugging .NET Core on Unix over SSH](https://devblogs.microsoft.com/devops/debugging-net-core-on-unix-over-ssh/) |
| 157 | +* [Quickstart: Debug ASP.NET with the Visual Studio debugger](/visualstudio/debugger/quickstart-debug-aspnet) |
| 158 | +* See [this GitHub issue](https://github.com/dotnet/AspNetCore.Docs/issues/2960) for more debugging information. |
| 159 | + |
| 160 | +:::moniker-end |
0 commit comments