Get exception code using C#

Last Reply one year ago By dharmendr

Posted one year ago

On page load I have some code within a try-catch block

If everything is ok and being processed I need it to return a repose status code of 200 and if there and error and it in the catch section also send a repose status code (i am not sure what the code for an error)

Here an example I found I need something like this

protected void Page_Load(object sender, System.EventArgs e)
{
    if (Common.CheckDatabaseConnection())
    {
        this.LiteralMachineName.Text = Environment.MachineName;
    }
    else
    {
        Response.ClearHeaders();
        Response.ClearContent();
        Response.Status = "503 ServiceUnavailable";
        Response.StatusCode = 503;
        Response.StatusDescription= "An error has occurred";
        Response.Flush();
        throw new HttpException(503,string.Format("An internal error occurred in the Application on {0}",Environment.MachineName)); 
    }
}