Handle Error in MVC
- Add customer errors in webconfig
Under
<system.web>
Add
<customErrors mode="On">
</customErrors>
2. In View
Under Shared Folder
Add
@{
Layout
= null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport"
content="width=device-width"
/>
<title>Error</title>
</head>
<body>
<h2>
Sorry, an error occurred while processing your request. Please Contact
Admin
</h2>
</body>
</html>
Error Handling Page
for HTTP Status Code404
- In Controller
Add
new Controller as Error Controller
Add then add
public ActionResult NotFound()
{
return
View();
}
- Then add view to shared folder and name it as NotFound
add header
@{
ViewBag.Title = "NotFound";
}
<h2>The Page your looking for cannot be Found.
Kindly Check</h2>
3. In <system.web>
Add
<customErrors mode="On">
<error statusCode="404" redirect="~/Error/NotFound"></error>
</customErrors>
Comments
Post a Comment