Tuesday, August 15, 2017

Custom error handling in a .NET application

Either:


            var context = HttpContext.Current;
            var exception = context.Server.GetLastError();
            context.Server.ClearError();    // Here is the new line.
            Response.Clear();
            Response.StatusCode = 200;
            Response.Write(@"<html><head></head><body>hello</body></html>");

            Response.End();
            return;

or:

            HttpContext.Current.ClearError();
            Response.Redirect("~/Error.aspx", false);
            return;


How to test: add this to the hostname: http://localhost:44100//%3Cwhscheck/


No comments:

Post a Comment