I am a newbie to MVC.
I am trying to create a custom error page to show when the user is looking for an unavailable resource. I followed a few articles and was able to show a custom error page. ASP.NET MVC 404 Error Handling.
I have created an error Controller with 'NotFound404()' action method and view is created with the same name 'NotFound404.cshtml'.
public class ErrorController : Controller
{
// GET: Error
public ActionResult NotFound404()
{
return View();
}
}
Web.config
<system.web>
<customErrors mode="On">
<error statusCode="404" redirect="~/Error/NotFound404"/>
</customErrors>
</system.web>
When I try to access any unknown resource, I can see the notfound404. But when I inspect URL it shows as 'http://localhost:xyzw/Error/NotFound404?aspxerrorpath=/New'.
Why do i get such weird URL? and I am not using any aspx pages but it shows aspx in the URL. HTTP status under F12-Developer tools- Network - shows 200 which isn't correct. How do I rectify this?
And when I tried to access any static HTML page instead of a new controller/ action-view
<system.web>
<customErrors mode="On">
<error statusCode="404" redirect="~/Shared/NotFound.html"/>
</customErrors>
</system.web>
404 Error occurs -- is this error because it is looking up for wrong path?
How do I fix these errors?
Please show a right way to configure these error handling strategies.
Thanks in advance.