Handle Error in MVC

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


  1. In Controller
    Add new Controller as Error Controller
Add then add
public ActionResult NotFound()
       {
            return View();
        }
  1. 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

Popular posts from this blog

How to retain the data annotations or class during modify a table in the database

Interview Questions

AJAX CONTROL