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.
redirect="/Shared/NotFound.html".~in your URLs. This might be slightly different to your exact issue but the following config will allow you to configure custom errors without the URL changing (usinghttpErrorsinstead ofCustomErrors) stackoverflow.com/a/32117966/4457454redirect="/Shared/NotFound.html"and when i try accessing any unknown resource, it still shows HTTP404 error screen.