![](/img/trans.png)
[英]How to resolve unable to acquire singleton lock issue in Azure WebJob?
[英]Why the browser is unable to find my views and how to resolve this issue?
我有一個 ASP.NET Core 6 MVC 項目。 我需要有關未處理異常的幫助。 我收到了錯誤視圖頁面和錯誤 controller。有人可以告訴我為什么會出現此錯誤以及如何修復它嗎?
處理請求時發生未處理的異常。 InvalidOperationException:未找到視圖“錯誤”。 搜索了以下位置:/Views/Error/Error.cshtml /Views/Shared/Error.cshtml /Pages/Shared/Error.cshtml Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable<string> originalLocations)
這是我的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);
}
}
}
我得到了三個錯誤視圖我嘗試在瀏覽器中提取錯誤 404 和錯誤 500,所有這些包括我的錯誤視圖都給我同樣的錯誤。
錯誤視圖
@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 查看
@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 查看
@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>
瀏覽器告訴我它找不到我的錯誤視圖,但我有它們。 不確定為什么瀏覽器找不到我的錯誤視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.