C# 如何从中间件返回重定向/视图?
我想询问如何在我的C# 如何从中间件返回重定向/视图?,c#,asp.net-core,asp.net-core-mvc,C#,Asp.net Core,Asp.net Core Mvc,我想询问如何在我的handleExceptionSync方法中执行重定向或仅返回视图 public async Task Invoke(HttpContext ctx) { try { await next(ctx); } catch (Exception ex) { await HandleExceptionAsync(ctx, ex, next); } } private static async Task H
handleExceptionSync
方法中执行重定向或仅返回视图
public async Task Invoke(HttpContext ctx)
{
try
{
await next(ctx);
}
catch (Exception ex)
{
await HandleExceptionAsync(ctx, ex, next);
}
}
private static async Task HandleExceptionAsync(HttpContext context, Exception ex, RequestDelegate next)
{
Notify(ex.Message);
var result = new ViewResult { ViewName = "CustomError" };
??
}
我的工作如下:
context.Response.Redirect("/Home/Error");
其中,Home
和Error
分别是控制器和操作名称