From ca965d536278a4970ede0b88a92c6f218bfc5915 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 12 May 2021 10:16:49 +0300 Subject: Implemented a 404 not found page --- ExamTemplate/Web/Controllers/AccountController.cs | 6 +++--- ExamTemplate/Web/Controllers/HomeController.cs | 5 +++++ ExamTemplate/Web/Startup.cs | 1 + ExamTemplate/Web/Views/Shared/ErrorNotFound.cshtml | 10 ++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 ExamTemplate/Web/Views/Shared/ErrorNotFound.cshtml (limited to 'ExamTemplate/Web') diff --git a/ExamTemplate/Web/Controllers/AccountController.cs b/ExamTemplate/Web/Controllers/AccountController.cs index f970a2c..a7ad771 100644 --- a/ExamTemplate/Web/Controllers/AccountController.cs +++ b/ExamTemplate/Web/Controllers/AccountController.cs @@ -39,7 +39,7 @@ namespace ExamTemplate.Web.Controllers bool result = await this._userService.RegisterUserAsync(registerUserServiceModel); if (result) - return await Login(new LoginUserViewModel { + return await this.Login(new LoginUserViewModel { Username = registerUserServiceModel.Username, Password = registerUserServiceModel.Password }); @@ -86,7 +86,7 @@ namespace ExamTemplate.Web.Controllers UserServiceModel userServiceModel = await this._userService.GetUserByUsernameAsync(username); if (userServiceModel == default(UserServiceModel)) - return RedirectToAction("Login"); + return RedirectToAction("ErrorNotFound", "Home"); UserViewModel userViewModel = this._autoMapper.Map(userServiceModel); @@ -99,7 +99,7 @@ namespace ExamTemplate.Web.Controllers UserServiceModel userServiceModel = await this._userService.GetUserByClaimsAsync(this.HttpContext.User); if (userServiceModel == default(UserServiceModel)) - return RedirectToAction("Login"); + return RedirectToAction("ErrorNotFound", "Home"); EditUserViewModel editUserViewModel = this._autoMapper.Map(userServiceModel); diff --git a/ExamTemplate/Web/Controllers/HomeController.cs b/ExamTemplate/Web/Controllers/HomeController.cs index f35cb1e..d9cfc45 100644 --- a/ExamTemplate/Web/Controllers/HomeController.cs +++ b/ExamTemplate/Web/Controllers/HomeController.cs @@ -24,5 +24,10 @@ namespace ExamTemplate.Web.Controllers { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } + + public IActionResult ErrorNotFound() + { + return View(); + } } } diff --git a/ExamTemplate/Web/Startup.cs b/ExamTemplate/Web/Startup.cs index bfaab91..c294566 100644 --- a/ExamTemplate/Web/Startup.cs +++ b/ExamTemplate/Web/Startup.cs @@ -89,6 +89,7 @@ namespace ExamTemplate.Web endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); + endpoints.MapFallbackToController("ErrorNotFound", "Home"); }); /* diff --git a/ExamTemplate/Web/Views/Shared/ErrorNotFound.cshtml b/ExamTemplate/Web/Views/Shared/ErrorNotFound.cshtml new file mode 100644 index 0000000..39fc5ca --- /dev/null +++ b/ExamTemplate/Web/Views/Shared/ErrorNotFound.cshtml @@ -0,0 +1,10 @@ +@{ + ViewData["Title"] = "404: Not found!"; +} + +

+ 404: Not found! +

+

+ The page you're looking for couldn't be found! +

-- cgit v1.2.3