Skip to content

Instantly share code, notes, and snippets.

@wellwind
Created September 30, 2016 13:09
Show Gist options
  • Save wellwind/83b30a0e582569de65e8d4081e5c6f10 to your computer and use it in GitHub Desktop.
Save wellwind/83b30a0e582569de65e8d4081e5c6f10 to your computer and use it in GitHub Desktop.
Asp.Net MVC handle error sample
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_EndRequest()
{
if (Context.Response.StatusCode == 200)
{
return;
}
Response.Clear();
Response.ContentType = "text/json";
Response.Write(JsonConvert.SerializeObject(new {ErrorCode = Context.Response.StatusCode}));
Response.End();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment