I'm still new to MVC 3 and I'm struggling to create a nice error page for my application.
I've noticed the shared Error.cshtml view which is auto generated, what's it used for and how ?
Any links to implementing a simple single error page would be brilliant as well :-)
If a view isn't found in this location, then by convention the MVC runtime looks in the “Views\Shared”. This simple organization scheme works well for small projects, but can become quite unwieldy as the size of the web site grows and the shared folder becomes an ever larger dumping ground.
In the Model-View-Controller (MVC) pattern, the view handles the app's data presentation and user interaction. A view is an HTML template with embedded Razor markup. Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client.
In ASP.NET, error handling is done using the standard try catch approach or using application events.
That is already in place; you just aren't seeing it as by default raw errors are displayed if your request comes from the web-server itself - very useful for debugging. Remote visitors would see the default error.cshtml result:
Sorry, an error occurred while processing your request.
To see the error page even when local, ensure the customErrors mode is "On":
<customErrors mode="On"/>
You may need to add this to <system.web>
in web.config. But most commonly during debugging this is set to "RemoteOnly".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With