Asp.net core 如何在ASP.NET核心MVC中使用IEExceptionHandler?
我在项目中使用IEExceptionHandler时遇到问题 我需要安装任何NuGet软件包吗 当我尝试使用时,VisualStudio找不到引用。他问我是否要创建一个名为IEExceptionHandler的接口Asp.net core 如何在ASP.NET核心MVC中使用IEExceptionHandler?,asp.net-core,asp.net-core-mvc,Asp.net Core,Asp.net Core Mvc,我在项目中使用IEExceptionHandler时遇到问题 我需要安装任何NuGet软件包吗 当我尝试使用时,VisualStudio找不到引用。他问我是否要创建一个名为IEExceptionHandler的接口 using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; namespace Ev
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace EventMotors.Controllers
{
public class ErrorController : Controller
{
private readonly IExceptionHandler _exceptionHandler;
public ErrorController(IExceptionHandler exceptionHandler)
{
_exceptionHandler = exceptionHandler;
}
}
}
IEExceptionHandler
不在asp.net核心中。在错误操作中,您可以使用IEExceptionHandlerPathFeature
访问错误处理程序控制器或页面中的异常和原始请求路径:
var exceptionHandlerPathFeature =
HttpContext.Features.Get<IExceptionHandlerPathFeature>();
if (exceptionHandlerPathFeature?.Error is FileNotFoundException)
{
ExceptionMessage = "File error thrown";
}
if (exceptionHandlerPathFeature?.Path == "/index")
{
ExceptionMessage += " from home page";
}
var异常HandlerPathFeature=
HttpContext.Features.Get();
if(异常HandlerPathFeature?。错误为FileNotFoundException)
{
ExceptionMessage=“抛出文件错误”;
}
if(例外HandlerPathFeature?.Path==“/index”)
{
例外消息+=“来自主页”;
}
请参阅文件: