L A

L A

  • NA
  • 170
  • 171.1k

HTTP 404 : Resource Not found - Custom error

Mar 26 2018 1:35 PM
Hello,
 
I'm newbie to MVC, trying to create a custom error page and show when user is looking for resource which isn't available. Followed few articles and able to show an custom error page.
  • https://stackoverflow.com/questions/717628/asp-net-mvc-404-error-handling?answertab=votes#tab-top
I have created an Error Controller with 'NotFound404()' action method and view is created with the same name 'NotFound404.cshtml'.
  1. public class ErrorController : Controller  
  2. {  
  3.     // GET: Error  
  4.     public ActionResult NotFound404()  
  5.     {  
  6.         return View();  
  7.     }  
  8. }  
Web.config
  1. <system.web>  
  2.   <customErrors mode="On">  
  3.     <error statusCode="404" redirect="~/Error/NotFound404"/>  
  4.   customErrors>  
  5. system.web>  
When i try to access any unknown resource, i can see the notfound404.cshtml. But when i inspect url it shows as 'http://localhost:xyzw/Error/NotFound404?aspxerrorpath=/New'.
 
 
Why do i get such wierd url? and i'm not using any aspx pages but it shows aspx in url. HTTP status under F12-Developer tools- Network - shows 200 OK. which isn't correct. How to rectify this.
 
And when i tried to access any static html page instead of a new controller/ action-view
  1. <system.web>  
  2.   <customErrors mode="On">  
  3.     <error statusCode="404" redirect="~/Shared/NotFound.html"/>  
  4.   customErrors>  
  5. system.web>  
404 Error occurs
 
 
 
is this error because of looking up for wrong path.?
 
My application folder structure
 
How to fix these errors and please show a right way to configure these error handling strategies.
 
Thanks in advance. 

Answers (5)