diff --git a/VAR.WebFormsCore/Code/GlobalErrorHandler.cs b/VAR.WebFormsCore/Code/GlobalErrorHandler.cs index cf539b6..33bc5be 100644 --- a/VAR.WebFormsCore/Code/GlobalErrorHandler.cs +++ b/VAR.WebFormsCore/Code/GlobalErrorHandler.cs @@ -1,5 +1,6 @@ using System; using System.Text; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using VAR.WebFormsCore.Pages; @@ -9,42 +10,45 @@ namespace VAR.WebFormsCore.Code { #region Private methods - private static void ShowInternalError(HttpContext context, Exception ex) + private static async Task ShowInternalErrorAsync(HttpContext context, Exception ex) { - context.Response.StatusCode = 500; - //context.Response.Clear(); - - StringBuilder sbOutput = new StringBuilder(); - sbOutput.Append("
Message: {0}
", exAux.Message); - sbOutput.AppendFormat("StackTrace:
{0}", exAux.StackTrace);
- exAux = exAux.InnerException;
- }
+ context.Response.StatusCode = 500;
- // Fill response to 512 bytes to avoid browser "beauty" response of errors.
- long fillResponse = 512 - sbOutput.Length;
- if (fillResponse > 0)
- {
- sbOutput.Append("");
- }
- context.Response.WriteAsync(sbOutput.ToString());
+ // Fill response to 512 bytes to avoid browser "beauty" response of errors.
+ long fillResponse = 512 - sbOutput.Length;
+ if (fillResponse > 0)
+ {
+ sbOutput.Append("");
+ }
+
+ await context.Response.WriteAsync(sbOutput.ToString());
+ await context.Response.Body.FlushAsync();
+ }
+ catch { /* Nom nom nom */ }
}
#endregion Private methods
#region Public methods
- public static void HandleError(HttpContext context, Exception ex)
+ public static async Task HandleErrorAsync(HttpContext context, Exception ex)
{
try
{
@@ -52,10 +56,11 @@ namespace VAR.WebFormsCore.Code
//context.Response.Clear();
//context.Handler = frmError;
frmError.ProcessRequest(context);
+ await context.Response.Body.FlushAsync();
}
catch
{
- ShowInternalError(context, ex);
+ await ShowInternalErrorAsync(context, ex);
}
}
diff --git a/VAR.WebFormsCore/Code/GlobalRouterMiddleware.cs b/VAR.WebFormsCore/Code/GlobalRouterMiddleware.cs
index c10758a..1cb3e65 100644
--- a/VAR.WebFormsCore/Code/GlobalRouterMiddleware.cs
+++ b/VAR.WebFormsCore/Code/GlobalRouterMiddleware.cs
@@ -39,16 +39,11 @@ namespace VAR.WebFormsCore.Code
{
if (IsIgnoreException(ex) == false)
{
- try
- {
- // TODO: Implement better error logging
- Console.WriteLine("!!!!!!!!!!");
- Console.Write("Message: {0}\nStacktrace: {1}\n", ex.Message, ex.StackTrace);
+ // TODO: Implement better error logging
+ Console.WriteLine("!!!!!!!!!!");
+ Console.Write("Message: {0}\nStacktrace: {1}\n", ex.Message, ex.StackTrace);
- GlobalErrorHandler.HandleError(httpContext, ex);
- await httpContext.Response.Body.FlushAsync();
- }
- catch (Exception) { /* Nom nom nom */}
+ await GlobalErrorHandler.HandleErrorAsync(httpContext, ex);
}
}
diff --git a/VAR.WebFormsCore/Pages/FrmEcho.cs b/VAR.WebFormsCore/Pages/FrmEcho.cs
index 7ea1ccc..3073d86 100644
--- a/VAR.WebFormsCore/Pages/FrmEcho.cs
+++ b/VAR.WebFormsCore/Pages/FrmEcho.cs
@@ -8,11 +8,11 @@ namespace VAR.WebFormsCore.Pages
{
#region IHttpHandler
- public void ProcessRequest(HttpContext context)
+ public async void ProcessRequest(HttpContext context)
{
- context.Response.WriteAsync("");
- context.Response.WriteAsync(JsonWriter.WriteObject(context.Request, indent: true));
- context.Response.WriteAsync("");
+ await context.Response.WriteAsync("");
+ await context.Response.WriteAsync(JsonWriter.WriteObject(context.Request, indent: true));
+ await context.Response.WriteAsync("");
}
#endregion IHttpHandler
diff --git a/VAR.WebFormsCore/Pages/Page.cs b/VAR.WebFormsCore/Pages/Page.cs
index 87938cd..7552101 100644
--- a/VAR.WebFormsCore/Pages/Page.cs
+++ b/VAR.WebFormsCore/Pages/Page.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.AspNetCore.Http;
@@ -17,48 +18,59 @@ namespace VAR.WebFormsCore.Pages
public async void ProcessRequest(HttpContext context)
{
- StringWriter stringWriter = new();
-
- Context = context;
- Page = this;
-
- if (context.Request.Method == "POST")
+ try
{
- _isPostBack = true;
- }
+ StringWriter stringWriter = new();
- OnPreInit();
- if (context.Response.HasStarted) { return; }
+ Context = context;
+ Page = this;
- OnInit();
- if (context.Response.HasStarted) { return; }
-
- OnLoad();
- if (context.Response.HasStarted) { return; }
-
- if (_isPostBack)
- {
- List