【发布时间】:2020-05-15 22:10:56
【问题描述】:
有人可以确认app.UseExceptionHandler() 不适用于服务器端 blazor 吗?
我见过几种情况,我的自定义 ErrorHandler 没有捕捉到我的应用程序抛出的异常。示例代码
Startup.cs:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider)
{
...
app.UseExceptionHandler(new ExceptionHandlerOptions { ExceptionHandler = ErrorHandler.HandleError });
...
}
ErrorHandler.cs:
public static async Task HandleError(HttpContext context)
{
var error = context.Features.Get<IExceptionHandlerFeature>()?.Error;
var message = error?.Message ?? "[EXCEPTION NOT FOUND]";
return;
}
一个例子是当我的存储库抛出异常时:
The instance of entity type cannot be tracked because another instance with the same key value for {'Id'} is already being tracked
我的 MVC 解决方案正在捕获所有异常,并且它使用类似的 ErrorHandling 实现。
【问题讨论】:
标签: c# .net asp.net-core .net-core blazor