I have been searching a lot for the way that I can handle 404 error for redirect it to a page designed and named 404 error.
Some of the articles say that I should do some changes in Route config. I changed it and now below codes are my route.config but still, it does not work properly
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default2",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
//404 ERRORS:
routes.MapRoute(
name:"404-PageNotFound",
url: "{}",
new { controller = "Home", action = "Pagenotfound" }
);
}
I mean still, when I run the project and I type the wrong address, it shows default 404 page not the one I designed - Pagenotfound.cshtml
.