[英]Is there a way to throw a HttpException from codebehind in MVC asp.net core 2?
我正在尝试从MVC asp.net core 2 Web应用程序中的类中的代码中抛出一个简单的HttpException 404错误。
From documentation you could use StatusCodeResult
as the result: 从文档中,您可以使用
StatusCodeResult
作为结果:
public StatusCodeResult StatusCodeActionResult()
{
return StatusCode(404);
}
For more information see StatusCodeResult 有关更多信息,请参见StatusCodeResult
I created a middleware to handle custom exceptions but I think that's not the best performance wise approach since core team says it's not a good practice to throw exception to handle business logic. 我创建了一个用于处理自定义异常的中间件,但我认为这不是最佳的性能明智方法,因为核心团队表示,抛出异常来处理业务逻辑不是一个好习惯。 You can see the link from OlafW comments
您可以从OlafW评论中看到链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.