Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared error view in ASP.Net MVC 3, what's it for?

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 :-)

like image 552
Steffen Avatar asked Mar 05 '11 08:03

Steffen


People also ask

What is shared view in MVC?

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.

What is the purpose of view in an MVC application?

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.

What is used to handle an error in MVC?

In ASP.NET, error handling is done using the standard try catch approach or using application events.


1 Answers

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".

like image 147
Marc Gravell Avatar answered Oct 25 '22 06:10

Marc Gravell