Skip to content

Commit bcbb8af

Browse files
committed
General feedback
1 parent 2a55105 commit bcbb8af

File tree

10 files changed

+25
-114
lines changed

10 files changed

+25
-114
lines changed

src/Hosting/Hosting/src/GenericHost/GenericWebHostedService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ private RequestDelegate BuildErrorPageApplication(Exception exception)
185185
{
186186
context.Response.StatusCode = 500;
187187
context.Response.Headers["Cache-Control"] = "no-cache";
188+
context.Response.ContentType = "text/html; charset=utf-8";
188189
return errorPage.ExecuteAsync(context);
189190
};
190191
}

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ HANDLE g_hEventLog = NULL;
3030
bool g_fInProcessApplicationCreated = false;
3131
BYTE* g_errorPageContent;
3232
int g_errorPageLength;
33-
std::wstring g_exceptionEventLog;
3433
HINSTANCE g_hServerModule;
3534

3635
HRESULT

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "HostFxr.h"
1616

1717
IN_PROCESS_APPLICATION* IN_PROCESS_APPLICATION::s_Application = NULL;
18-
extern std::wstring g_exceptionEventLog;
1918

2019
IN_PROCESS_APPLICATION::IN_PROCESS_APPLICATION(
2120
IHttpServer& pHttpServer,
@@ -480,14 +479,6 @@ IN_PROCESS_APPLICATION::UnexpectedThreadExit(const ExecuteClrContext& context) c
480479

481480
if (context.m_exceptionCode != 0)
482481
{
483-
if (!g_exceptionEventLog.empty())
484-
{
485-
EventLog::Error(
486-
ASPNETCORE_EVENT_GENERAL_ERROR,
487-
g_exceptionEventLog.c_str()
488-
);
489-
}
490-
491482
if (!content.empty())
492483
{
493484
EventLog::Error(

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ extern bool g_fInProcessApplicationCreated;
1010
extern BYTE* g_errorPageContent;
1111
extern int g_errorPageLength;
1212
extern IHttpServer* g_pHttpServer;
13-
extern std::wstring g_exceptionEventLog;
1413

1514
//
1615
// Initialization export
@@ -522,12 +521,4 @@ http_set_startup_error_page_content(_In_ byte* errorPageContent, int length)
522521
}
523522
}
524523

525-
EXTERN_C __MIDL_DECLSPEC_DLLEXPORT
526-
VOID
527-
http_set_startup_error_event_log(_In_ LPCWSTR errorPageContent)
528-
{
529-
g_exceptionEventLog = std::wstring(errorPageContent);
530-
}
531-
// TODO log exception message here.
532-
533524
// End of export

src/Servers/IIS/IIS/src/Microsoft.AspNetCore.Server.IIS.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<Compile Include="$(SharedSourceRoot)Buffers.MemoryPool\**\*.cs" />
18-
<Compile Include="$(SharedSourceRoot)HttpSys\**\*.cs" />
17+
<Compile Include="$(SharedSourceRoot)Buffers.MemoryPool\**\*.cs" LinkBase="Shared\" />
18+
<Compile Include="$(SharedSourceRoot)HttpSys\**\*.cs" LinkBase="Shared\"/>
19+
<Compile Include="$(SharedSourceRoot)StackTrace\**\*.cs" LinkBase="Shared\" />
20+
<Compile Include="$(SharedSourceRoot)RazorViews\*.cs" LinkBase="Shared\" />
21+
<Compile Include="$(SharedSourceRoot)ErrorPage\*.cs" LinkBase="Shared\" />
1922
</ItemGroup>
2023

2124
<Target Name="ValidateNativeComponentsBuilt" AfterTargets="Build" >
@@ -36,9 +39,6 @@
3639
<Reference Include="Microsoft.Extensions.TypeNameHelper.Sources" />
3740
<Reference Include="System.IO.Pipelines" />
3841
<Reference Include="System.Security.Principal.Windows" />
39-
<Compile Include="$(SharedSourceRoot)StackTrace\**\*.cs" />
40-
<Compile Include="$(SharedSourceRoot)RazorViews\*.cs" />
41-
<Compile Include="$(SharedSourceRoot)ErrorPage\*.cs" />
4242
</ItemGroup>
4343

4444
<Import Project="..\..\build\assets.props" />

src/Servers/IIS/IIS/src/NativeMethods.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@ private static extern unsafe int http_websockets_write_bytes(
150150
[DllImport(AspNetCoreModuleDll)]
151151
private static extern unsafe int http_set_startup_error_page_content(byte* content, int contentLength);
152152

153-
[DllImport(AspNetCoreModuleDll)]
154-
private static extern void http_set_startup_error_event_log([MarshalAs(UnmanagedType.LPWStr)]string content);
155-
156153
public static void HttpPostCompletion(IntPtr pInProcessHandler, int cbBytes)
157154
{
158155
Validate(http_post_completion(pInProcessHandler, cbBytes));
@@ -311,11 +308,6 @@ internal static unsafe void HttpSetStartupErrorPageContent(byte[] content)
311308
}
312309
}
313310

314-
internal static void HttpSetStartupExceptionEventLogMessage(string content)
315-
{
316-
http_set_startup_error_event_log(content);
317-
}
318-
319311
private static void Validate(int hr)
320312
{
321313
if (hr != HR_OK)

src/Servers/IIS/IIS/src/StartupHook.cs

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -60,93 +60,15 @@ public static void Initialize()
6060
var errorPage = new ErrorPage(model);
6161

6262
// Create a temporary HttpContext to write the response into.
63-
var context = new IntermediateHttpContext();
63+
var stream = new MemoryStream();
6464
// Sync over async here, but you can't have async code in startup hooks.
65-
errorPage.ExecuteAsync(context).GetAwaiter().GetResult();
65+
errorPage.ExecuteAsync(stream).GetAwaiter().GetResult();
6666

6767
// Get the raw content and set the error page.
68-
var stream = (MemoryStream)context.Response.Body;
6968
stream.Position = 0;
7069
var content = stream.ToArray();
7170

7271
NativeMethods.HttpSetStartupErrorPageContent(content);
73-
74-
// Second part of startup hook is sending to event log.
75-
var stringBuilder = new StringBuilder();
76-
stringBuilder.Append("Application: " + Environment.NewLine); // TODO dll name
77-
stringBuilder.Append("CoreCLR Version: " + clrVersion + Environment.NewLine);
78-
stringBuilder.Append("Description: The process was terminated due to an unhandled exception." + Environment.NewLine);
79-
stringBuilder.Append($"Exception Info: {exception.GetType().ToString()}: {exception.Message}" + Environment.NewLine);
80-
stringBuilder.Append(exception.StackTrace);
81-
82-
NativeMethods.HttpSetStartupExceptionEventLogMessage(stringBuilder.ToString());
8372
};
8473
}
85-
86-
private class IntermediateHttpContext : HttpContext
87-
{
88-
public IntermediateHttpContext()
89-
{
90-
}
91-
92-
public override IFeatureCollection Features => throw new NotImplementedException();
93-
94-
public override HttpRequest Request => null;
95-
96-
public override HttpResponse Response { get; } = new IntermediateResponse();
97-
98-
public override ConnectionInfo Connection => throw new NotImplementedException();
99-
100-
public override WebSocketManager WebSockets => throw new NotImplementedException();
101-
102-
public override ClaimsPrincipal User { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
103-
public override IDictionary<object, object> Items { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
104-
public override IServiceProvider RequestServices { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
105-
public override CancellationToken RequestAborted { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
106-
public override string TraceIdentifier { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
107-
public override ISession Session { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
108-
109-
public override void Abort()
110-
{
111-
throw new NotImplementedException();
112-
}
113-
114-
private class IntermediateResponse : HttpResponse
115-
{
116-
public override HttpContext HttpContext => throw new NotImplementedException();
117-
118-
public override int StatusCode { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
119-
120-
public override IHeaderDictionary Headers => throw new NotImplementedException();
121-
122-
public override Stream Body { get; set; } = new MemoryStream();
123-
public override PipeWriter BodyWriter { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
124-
public override long? ContentLength { get; set; }
125-
public override string ContentType { get; set; }
126-
127-
public override IResponseCookies Cookies => throw new NotImplementedException();
128-
129-
public override bool HasStarted => throw new NotImplementedException();
130-
131-
public override void OnCompleted(Func<object, Task> callback, object state)
132-
{
133-
throw new NotImplementedException();
134-
}
135-
136-
public override void OnStarting(Func<object, Task> callback, object state)
137-
{
138-
throw new NotImplementedException();
139-
}
140-
141-
public override void Redirect(string location, bool permanent)
142-
{
143-
throw new NotImplementedException();
144-
}
145-
146-
public override Task StartAsync(CancellationToken cancellationToken = default)
147-
{
148-
throw new NotImplementedException();
149-
}
150-
}
151-
}
15274
}

src/Shared/ErrorPage/ErrorPage.Designer.cs

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Shared/ErrorPage/ErrorPage.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
public ErrorPageModel Model { get; set; }
1616
}
1717
@{
18-
Response.ContentType = "text/html; charset=utf-8";
1918
var location = string.Empty;
2019
}
2120
<!DOCTYPE html>

src/Shared/RazorViews/BaseView.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ internal abstract class BaseView
5757
/// </summary>
5858
protected JavaScriptEncoder JavaScriptEncoder { get; set; } = JavaScriptEncoder.Default;
5959

60+
61+
/// <summary>
62+
/// Execute an individual request
63+
/// </summary>
64+
/// <param name="stream">The stream to write to</param>
65+
public async Task ExecuteAsync(Stream stream)
66+
{
67+
// We technically don't need this intermediate buffer if this method accepts a memory stream.
68+
var buffer = new MemoryStream();
69+
Output = new StreamWriter(buffer, UTF8NoBOM, 4096, leaveOpen: true);
70+
await ExecuteAsync();
71+
await Output.FlushAsync();
72+
Output.Dispose();
73+
buffer.Seek(0, SeekOrigin.Begin);
74+
await buffer.CopyToAsync(stream);
75+
}
76+
6077
/// <summary>
6178
/// Execute an individual request
6279
/// </summary>

0 commit comments

Comments
 (0)