Created
November 11, 2014 07:15
-
-
Save RhysC/0e57826d103df40e2b90 to your computer and use it in GitHub Desktop.
Error Handling 404 in Asp.Net MVC 5
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
| using System.Web.Mvc; | |
| namespace YourWebsite.Filters | |
| { | |
| public class ObjectNotFoundExceptionFilterAttribute : ActionFilterAttribute, IExceptionFilter | |
| { | |
| public void OnException(ExceptionContext filterContext) | |
| { | |
| if (filterContext.Exception is NHibernate.ObjectNotFoundException) | |
| { | |
| filterContext.Result = new HttpNotFoundResult("Entity not found"); | |
| filterContext.ExceptionHandled = true; | |
| } | |
| } | |
| } | |
| } |
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
| ... | |
| <system.web> | |
| <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="/Error"> | |
| <error statusCode="404" redirect="NotFound"/> | |
| </customErrors> | |
| <!-- other stuff here-- > | |
| </system.web> | |
| <system.webServer> | |
| <httpErrors errorMode="Custom" existingResponse="Replace"> | |
| <remove statusCode="404" /> | |
| <error statusCode="404" responseMode="ExecuteURL" path="/NotFound" /> | |
| </httpErrors> | |
| <!-- other stuff here-- > | |
| </system.webServer> | |
| ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment