Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 如何在ASP.NET核心MVC中使用IEExceptionHandler?_Asp.net Core_Asp.net Core Mvc - Fatal编程技术网

Asp.net core 如何在ASP.NET核心MVC中使用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

我在项目中使用IEExceptionHandler时遇到问题

我需要安装任何NuGet软件包吗

当我尝试使用时,VisualStudio找不到引用。他问我是否要创建一个名为IEExceptionHandler的接口

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”)
{
例外消息+=“来自主页”;
}
请参阅文件: