[英]Why the browser is unable to find my views and how to resolve this issue?
I have an ASP.NET Core 6 MVC project.我有一个 ASP.NET Core 6 MVC 项目。 I need help with an unhandled exception.
我需要有关未处理异常的帮助。 I got my error view pages and error controller. Could somebody tell me why I am getting this error and how to fix it?
我收到了错误视图页面和错误 controller。有人可以告诉我为什么会出现此错误以及如何修复它吗?
An unhandled exception occurred while processing the request.
处理请求时发生未处理的异常。 InvalidOperationException: The view 'Error' was not found.
InvalidOperationException:未找到视图“错误”。 The following locations were searched: /Views/Error/Error.cshtml /Views/Shared/Error.cshtml /Pages/Shared/Error.cshtml Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable<string> originalLocations)
搜索了以下位置:/Views/Error/Error.cshtml /Views/Shared/Error.cshtml /Pages/Shared/Error.cshtml Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable<string> originalLocations)
This is my ErrorController
:这是我的
ErrorController
:
using System.Diagnostics;
using ArtGallery.Web.ViewModels;
using Microsoft.AspNetCore.Mvc;
using NuGet.Protocol.Plugins;
namespace ArtGallery.Web.Controllers
{
public class ErrorController : BaseController
{
[Route("/Error/Error")]
public IActionResult Error()
{
return this.View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? this.HttpContext.TraceIdentifier });
}
[Route("/Error/404")]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error404()
{
var errorModel = new ErrorViewModel
{
StatusCode = StatusCodes.Status404NotFound,
RequestId = Activity.Current?.Id ?? this.HttpContext.TraceIdentifier,
};
return View(errorModel);
}
[Route("/Error/500")]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error500()
{
var errorModel = new ErrorViewModel
{
StatusCode = StatusCodes.Status500InternalServerError,
RequestId = Activity.Current?.Id ?? this.HttpContext.TraceIdentifier,
};
return View(errorModel);
}
}
}
I got three Error Views I try to pull Error 404 and Error 500 in the Browsers, all of them including my Error View gives me the same error.我得到了三个错误视图我尝试在浏览器中提取错误 404 和错误 500,所有这些包括我的错误视图都给我同样的错误。
Error View错误视图
@model ErrorViewModel
@{
ViewData["Title"] = "Error";
}
<div class="container">
<div class="error-page">
<div class="error-content text">
<h1 class="text-danger" style="color: ffea00">Oops, Error!</h1>
<p class="text-danger">Something went wrong while processing your request.</p>
</div>
<strong>Status code:</strong> <code>Model.StatusCode</code>
@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}
</div>
</div>
Error404 View Error404 查看
@using ArtGallery.Common
@model ArtGallery.Web.ViewModels.ErrorViewModel
@{
ViewData["Title"] = "404";
}
<div class="container">
<div class="error-page">
<div class="error-content image">
<img src="@GlobalConstants.Images.Error404" class="img-thumbnail" />
</div>
<div class="error-content text">
<h1 class="text-danger" style="color: darkblue">Oops!</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
<span>We are sorry, the page you are looking is not found or temporarlly unavailable. Please go back to Home Page. Thank you for your undestanding!</span>
</div>
<div class="btn btn-primary">
<a class="nav-link text-white" href="/">GO HOME PAGE</a>
</div>
</div>
</div>
Error500 View Error500 查看
@using ArtGallery.Common
@model ArtGallery.Web.ViewModels.ErrorViewModel
@{
ViewData["Title"] = "500";
}
<div class="container">
<div class="error-page">
<div class="error-content image">
<img src="@GlobalConstants.Images.Error500" class="img-thumbnail" />
</div>
<div class="error-content text">
<h1 class="text-danger" style="color: darkblue">Oops!</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
<span>We will work on fixing that right away. Meanwhile, please go back to Home Page. Thank you for your undestanding!</span>
</div>
<div class="btn btn-primary">
<a class="nav-link text-white" href="/">GO HOME PAGE</a>
</div>
</div>
</div>
The Browser is telling me that it could not find my Error Views but they are there I have them.浏览器告诉我它找不到我的错误视图,但我有它们。 Not sure why the Browser could not find my Error Views.
不确定为什么浏览器找不到我的错误视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.