In this article, I will show you how to add custom error page in web config using asp.net MVC. If application got any error you can invoke asp.net 404 page.
Step 1: Create an empty asp.net mvc project and Right click on the "Controllers" folder and add "Home" controller. Copy and paste the following code.
[HandleError()]
public ActionResult Index()
{
string UserId = Session["UserId"].ToString();
return View();
}
Step 2: Right click on the Share folder and create a view named as error. Copy and paste the following code.
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>404</title>
</head>
<body>
<hgroup>
<h1 style="color:red">404</h1>
<h2>An error occurred while processing your request.</h2>
</hgroup>
</body>
</html>
Step 3: Set custom error mode in Web.config file like this:
<system.web>
<customErrors mode="On" ></customErrors>
<httpRuntime targetFramework="4.5" />
<!--
other Coding
-->
</system.web>
Description:
When you run the application the asp.net mvc return custom error page will show like this,
Post your comments / questions
Recent Article
- How to fix HAXM is not installed |in Android Studio
- How to fix CMOS Checksum Error in Computer or Laptop | SOLVED
- Reactivating windows after a Hardware change on PC or Laptop
- FIXED: Windows reported that the hardware of your device has changed. Error code :0xc004F211
- "redirect" is not defined pylance("reportUndefinedVariable)
- This action cannot be completed because the file is open in SQL Server(SQLEXPRESS) - FIXED
- Unicode error 'unicodeescape' codec can't decode bytes in position 2-3: truncated UXXXXXXXX escape
- Could not find the 'angular-devkit/build-angular:dev-server' builder's node package | Angular Error
Related Article