【发布时间】:2019-07-27 10:09:36
【问题描述】:
我有一个非常简单的异常,由 VS2017 为 razor pages .net core 生成的默认错误页面处理。 错误页面显示异常错误 - 有什么方法可以显示自定义错误,例如“命令中的错误重试”
try
{
var interenet = "nc -w 5 -z 8.8.8.8 53 >/dev/null 2>&1 && echo 'ok' || echo 'error'".Bash();
}
catch (Exception ex2)
{
_logger.LogError(
0, ex2,
"An exception was thrown attempting " +
"to execute the error handler.");
throw new Exception(ex2.Message);
}
错误页面模型
public class ErrorModel : PageModel
{
public string RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
我添加的启动类
app.UseExceptionHandler("/Error");
【问题讨论】:
标签: c# razor error-handling middleware razor-pages