Skip to content

Commit 84230ae

Browse files
Merge pull request #104 from DiyorMarket/Added_ErrorPage
Added Error pages
2 parents e9d91af + d3655f8 commit 84230ae

12 files changed

+267
-28
lines changed

CheckDrive.Web/CheckDrive.Web/CheckDrive.Web.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<Compile Include="Controllers\DoctorReviewsController.cs" />
2020
<Compile Include="Controllers\DoctorsController.cs" />
2121
<Compile Include="Controllers\DriversController.cs" />
22+
<Compile Include="Controllers\ErrorController.cs" />
2223
<Compile Include="Controllers\RolesController.cs" />
2324
<Compile Include="Controllers\MechanicAcceptancesController.cs" />
2425
<Compile Include="Controllers\MechanicHandoversController.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace CheckDrive.Web.Controllers
4+
{
5+
public class ErrorController : Controller
6+
{
7+
public IActionResult Index()
8+
{
9+
return View();
10+
}
11+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
12+
public IActionResult ErrorPage(int statusCode)
13+
{
14+
return statusCode switch
15+
{
16+
401 => RedirectToAction(nameof(Unauthorized)),
17+
403 => RedirectToAction(nameof(Forbidden)),
18+
404 => RedirectToAction(nameof(NotFound)),
19+
_ => RedirectToAction(nameof(InternalServerError)),
20+
};
21+
}
22+
23+
public IActionResult Unauthorized()
24+
{
25+
return View();
26+
}
27+
28+
public IActionResult Forbidden()
29+
{
30+
return View();
31+
}
32+
33+
public IActionResult NotFound()
34+
{
35+
return View();
36+
}
37+
38+
public IActionResult InternalServerError()
39+
{
40+
return View();
41+
}
42+
43+
}
44+
}

CheckDrive.Web/CheckDrive.Web/Filters/ApiExceptionFilter.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@ public void OnException(ExceptionContext context)
1111
if (context.Exception is ApiException exception)
1212
{
1313
int statusCode = (int)exception.StatusCode;
14-
if (statusCode == 401)
15-
{
16-
context.Result = new RedirectToActionResult("Index", "Auth", new { statusCode });
17-
}
18-
14+
context.Result = new RedirectToActionResult("ErrorPage", "Error", new { statusCode });
1915
context.ExceptionHandled = true;
2016
}
2117
else
2218
{
23-
context.Result = new RedirectToActionResult("Error", "Home", new { statusCode = 500 });
19+
context.Result = new RedirectToActionResult("ErrorPage", "Error", new { statusCode = 500 });
2420
context.ExceptionHandled = true;
2521
}
2622
}

CheckDrive.Web/CheckDrive.Web/Views/Shared/Error.cshtml

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@{
2+
ViewBag.Title = "Forbidden";
3+
Layout = "~/Views/Shared/_PersonalLayout.cshtml";
4+
}
5+
6+
<!DOCTYPE html>
7+
<html>
8+
<head>
9+
<title>@ViewBag.Title</title>
10+
<style>
11+
body {
12+
font-family: Arial, sans-serif;
13+
position: relative;
14+
min-height: 100vh;
15+
margin: 0;
16+
padding: 0;
17+
}
18+
19+
.container {
20+
text-align: center;
21+
padding-top: 50px; /* Add 50 pixels padding at the top */
22+
}
23+
24+
img {
25+
max-width: 100%;
26+
height: auto;
27+
}
28+
29+
.button-container {
30+
position: fixed;
31+
bottom: 20px;
32+
right: 20px;
33+
}
34+
35+
.button-container a {
36+
display: inline-block;
37+
padding: 10px 20px;
38+
font-size: 16px;
39+
cursor: pointer;
40+
background-color: #F62D2D;
41+
color: white;
42+
text-decoration: none;
43+
border: none;
44+
border-radius: 5px;
45+
}
46+
</style>
47+
</head>
48+
<body>
49+
<div class="container">
50+
<img src="~/images/Forbidden.png"/>
51+
</div>
52+
<div class="button-container">
53+
<a href="@Url.Action("Login", "Auth")">Login</a>
54+
</div>
55+
</body>
56+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
@{
2+
ViewBag.Title = "Internal Server Error";
3+
Layout = "~/Views/Shared/_PersonalLayout.cshtml";
4+
}
5+
6+
<!DOCTYPE html>
7+
<html>
8+
<head>
9+
<title>@ViewBag.Title</title>
10+
<style>
11+
body {
12+
font-family: Arial, sans-serif;
13+
position: relative;
14+
min-height: 100vh;
15+
margin: 0;
16+
padding: 0;
17+
}
18+
19+
.container {
20+
text-align: center;
21+
padding-top: 50px; /* Add 50 pixels padding at the top */
22+
}
23+
24+
img {
25+
max-width: 100%;
26+
height: auto;
27+
}
28+
29+
.button-container {
30+
position: fixed;
31+
bottom: 20px;
32+
right: 20px;
33+
}
34+
35+
.button-container a {
36+
display: inline-block;
37+
padding: 10px 20px;
38+
font-size: 16px;
39+
cursor: pointer;
40+
background-color: #F62D2D;
41+
color: white;
42+
text-decoration: none;
43+
border: none;
44+
border-radius: 5px;
45+
}
46+
</style>
47+
</head>
48+
<body>
49+
<div class="container">
50+
<img src="~/images/InternalServerError.png" />
51+
</div>
52+
</body>
53+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@{
2+
ViewBag.Title = "Not Found";
3+
Layout = "~/Views/Shared/_PersonalLayout.cshtml";
4+
}
5+
<!DOCTYPE html>
6+
<html>
7+
<head>
8+
<title>@ViewBag.Title</title>
9+
<style>
10+
body {
11+
font-family: Arial, sans-serif;
12+
position: relative;
13+
min-height: 100vh;
14+
margin: 0;
15+
padding: 0;
16+
}
17+
18+
.container {
19+
text-align: center;
20+
padding-top: 50px; /* Add 50 pixels padding at the top */
21+
}
22+
23+
img {
24+
max-width: 100%;
25+
height: auto;
26+
}
27+
28+
.button-container {
29+
position: fixed;
30+
bottom: 20px;
31+
right: 20px;
32+
}
33+
34+
.button-container a {
35+
display: inline-block;
36+
padding: 10px 20px;
37+
font-size: 16px;
38+
cursor: pointer;
39+
background-color: #F62D2D;
40+
color: white;
41+
text-decoration: none;
42+
border: none;
43+
border-radius: 5px;
44+
}
45+
</style>
46+
</head>
47+
<body>
48+
<div class="container">
49+
<img src="~/images/NotFound.png" alt="Description of the image" />
50+
</div>
51+
<div class="button-container">
52+
<a href="@Url.Action("Index", "Dashboard")">Bosh Sahifaga Qaytish</a>
53+
</div>
54+
</body>
55+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@{
2+
ViewBag.Title = "Unauthorized";
3+
Layout = "~/Views/Shared/_PersonalLayout.cshtml";
4+
}
5+
6+
<!DOCTYPE html>
7+
<html>
8+
<head>
9+
<title>@ViewBag.Title</title>
10+
<style>
11+
body {
12+
font-family: Arial, sans-serif;
13+
position: relative;
14+
min-height: 100vh;
15+
margin: 0;
16+
padding: 0;
17+
}
18+
19+
.container {
20+
text-align: center;
21+
padding-top: 50px; /* Add 50 pixels padding at the top */
22+
}
23+
24+
img {
25+
max-width: 100%;
26+
height: auto;
27+
}
28+
29+
.button-container {
30+
position: fixed;
31+
bottom: 20px;
32+
right: 20px;
33+
}
34+
35+
.button-container a {
36+
display: inline-block;
37+
padding: 10px 20px;
38+
font-size: 16px;
39+
cursor: pointer;
40+
background-color: #007bff;
41+
color: white;
42+
text-decoration: none;
43+
border: none;
44+
border-radius: 5px;
45+
}
46+
</style>
47+
</head>
48+
<body>
49+
<div class="container">
50+
<img src="~/images/Unauthorized.png" />
51+
</div>
52+
<div class="button-container">
53+
<a href="@Url.Action("Login", "Auth")">Loginga qaytish</a>
54+
</div>
55+
</body>
56+
</html>
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)