My project in MVC 5.i wanted to handel 404. i did it but problem is that
When I access the view using the following URL, everything works fine and as expected:
http://localhost/Hotels/Index30701000000 But when I access the view using following URL, I get 404.0 error message (error shown below)
http://localhost/Hotels/Edit/09099999dfdfb http://localhost/Hotels/Edit/090/20130701000000 Error: HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
My code is
Controller
public class ErrorController : Controller { // GET: Error public ActionResult Unauthorized() { Response.StatusCode = 404; Response.TrySkipIisCustomErrors = true; return View(); } } RouteConfig
routes.MapRoute( name: "Unauthorized", url: "Unauthorized/{action}/{id}", defaults: new { controller = "Error", action = "Unauthorized", id = UrlParameter.Optional } ); Global.asax
protected void Application_Error() { Exception exception = Server.GetLastError(); HttpException httpException = exception as HttpException; } webconfig
<system.web> <customErrors mode="On" defaultRedirect="Error"> <error statusCode="404" redirect="Unauthorized" /> </customErrors> </system.web> View //Unauthorized.cshtml
@model System.Web.Mvc.HandleErrorInfo @{ ViewBag.Title = "Unauthorized"; } <h1>Page Not Found!</h1>
C#, but why dont't you edit your server settings so it redirects every404to your custom page?