如何防止 IIS 使用 IIS 默认错误页面覆盖自定义错误页面?是否有 Response.TrySkipIisCustomErrors 等效于 asp.net 核心?在 ASP Net MVC 中,我使用下面的代码在没有自定义页面的情况下发送错误,但在 asp net core 中它不起作用。
try
{
// some code
}
catch (Exception ex)
{
Response.TrySkipIisCustomErrors = true;
Response.StatusCode = (int)HttpStatusCode.InternalServerError;
mensagem = ex.Message;
}
Run Code Online (Sandbox Code Playgroud)
听起来您正在尝试禁用特定请求的状态代码错误页面。ASP.NET Core 处理错误文档为您提供了答案。
它不像旧TrySkipIisCustomErrors标志那么简洁,但可能更清楚实际发生的情况:
var statusCodePagesFeature =
HttpContext.Features.Get<IStatusCodePagesFeature>();
if (statusCodePagesFeature is not null)
{
statusCodePagesFeature.Enabled = false;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2155 次 |
| 最近记录: |