Skip to content

Commit 1b40747

Browse files
committed
Update debug code to not use Startup /2
1 parent 7fedeb4 commit 1b40747

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

aspnetcore/test/troubleshoot.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,86 @@ To obtain the environment, use either of the following approaches:
8383

8484
* Assign the environment to a property in `Program.cs`. Check the environment using the property, for example, `if (app.Environment.IsDevelopment())`.
8585

86+
87+
```csharp
88+
public void Configure(IApplicationBuilder app, IHostingEnvironment env,
89+
IConfiguration config)
90+
{
91+
if (env.IsDevelopment())
92+
{
93+
app.Run(async (context) =>
94+
{
95+
var sb = new StringBuilder();
96+
var nl = System.Environment.NewLine;
97+
var rule = string.Concat(nl, new string('-', 40), nl);
98+
99+
100+
var authSchemeProvider = app.Services.GetRequiredService<IAuthenticationSchemeProvider>();
101+
102+
sb.Append($"Request{rule}");
103+
sb.Append($"{DateTimeOffset.Now}{nl}");
104+
sb.Append($"{context.Request.Method} {context.Request.Path}{nl}");
105+
sb.Append($"Scheme: {context.Request.Scheme}{nl}");
106+
sb.Append($"Host: {context.Request.Headers["Host"]}{nl}");
107+
sb.Append($"PathBase: {context.Request.PathBase.Value}{nl}");
108+
sb.Append($"Path: {context.Request.Path.Value}{nl}");
109+
sb.Append($"Query: {context.Request.QueryString.Value}{nl}{nl}");
110+
111+
sb.Append($"Connection{rule}");
112+
sb.Append($"RemoteIp: {context.Connection.RemoteIpAddress}{nl}");
113+
sb.Append($"RemotePort: {context.Connection.RemotePort}{nl}");
114+
sb.Append($"LocalIp: {context.Connection.LocalIpAddress}{nl}");
115+
sb.Append($"LocalPort: {context.Connection.LocalPort}{nl}");
116+
sb.Append($"ClientCert: {context.Connection.ClientCertificate}{nl}{nl}");
117+
118+
sb.Append($"Identity{rule}");
119+
sb.Append($"User: {context.User.Identity.Name}{nl}");
120+
var scheme = await authSchemeProvider
121+
.GetSchemeAsync(IISDefaults.AuthenticationScheme);
122+
sb.Append($"DisplayName: {scheme?.DisplayName}{nl}{nl}");
123+
124+
sb.Append($"Headers{rule}");
125+
foreach (var header in context.Request.Headers)
126+
{
127+
sb.Append($"{header.Key}: {header.Value}{nl}");
128+
}
129+
sb.Append(nl);
130+
131+
sb.Append($"WebSockets{rule}");
132+
if (context.Features.Get<IHttpUpgradeFeature>() != null)
133+
{
134+
sb.Append($"Status: Enabled{nl}{nl}");
135+
}
136+
else
137+
{
138+
sb.Append($"Status: Disabled{nl}{nl}");
139+
}
140+
141+
sb.Append($"Configuration{rule}");
142+
var config = builder.Configuration;
143+
144+
foreach (var pair in config.AsEnumerable())
145+
{
146+
sb.Append($"{pair.Key}: {pair.Value}{nl}");
147+
}
148+
sb.Append(nl);
149+
sb.Append(nl);
150+
151+
sb.Append($"Environment Variables{rule}");
152+
var vars = System.Environment.GetEnvironmentVariables();
153+
foreach (var key in vars.Keys.Cast<string>().OrderBy(key => key,
154+
StringComparer.OrdinalIgnoreCase))
155+
{
156+
var value = vars[key];
157+
sb.Append($"{key}: {value}{nl}");
158+
}
159+
160+
context.Response.ContentType = "text/plain";
161+
await context.Response.WriteAsync(sb.ToString());
162+
});
163+
}
164+
```
165+
86166
:::code language="csharp" source="~/test/troubleshoot/code/9.x/Program.cs" highlight="13-85":::
87167

88168
## Debug ASP.NET Core apps

0 commit comments

Comments
 (0)