Created
September 30, 2016 13:09
-
-
Save wellwind/83b30a0e582569de65e8d4081e5c6f10 to your computer and use it in GitHub Desktop.
Asp.Net MVC handle error sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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