"Thread was being aborted" problem ?


Recently I've got this error on my Asp.NET application and I found this way by myself to solve it :


public static void WriteJSONObject(this HttpResponse response, object content) 
{
            response.ContentType = "application/json";
            response.Write(new JavaScriptSerializer().Serialize(content));
            response.End();
}

public void RegisterUser() 
{
    try 
    {
       Response.WriteJSONObject(new { Result = "See hello" });
    } 
    catch (Exception err) 
    {
        if (err.Message != "Thread was being aborted.")
            Response.WriteJSONObject(new { Result = err.Message });
        else 
        {
            Response.End();
        }
    }
}

0 comments: