问题描述
所以,我从我的MVC的Web应用程序的详细返回400错误响应。设置existingResponse =直通的作品,但是这不是我想要的。我不希望暴露所有的失败,我只是想揭露他们时,我有自定义的响应。
汽车,是默认设置,但我特意设置。然而,文件说,SetStatus标志必须设置,但我不知道怎么做这样的事情。我写了以下四个控制器方法,以测试它,只有BadRequestD工作。其他人设置状态code和状态就好了,但身体内容是错误的请求。
公众的ActionResult BadRequestA()
{
Response.Status code = 400;
返回内容(weeeeee);
}公众的ActionResult BadRequestB()
{
Response.Status =400单位DUN搞砸了;
返回内容(weeeeee);
}公众的ActionResult BadRequestC()
{
Response.Status =400单位DUN搞砸了;
Response.Status code = 400;
返回内容(weeeeee);
}公众的ActionResult BadRequestD()
{
Response.Status code = 400;
Response.TrySkipIisCustomErrors = TRUE;
返回内容(weeeeee);
}
It's actually talking about the fTrySkipCustomErrors
flag/argument to the IHttpResponse::SetStatus
method in the IIS C++ SDK (see note I added to bottom of documentation here). But in ASP.NET the flag is exposed as Response.TrySkipIisCustomErrors
. So according to:
I would expect to see IIS replace the response with its own html error page content (you can configure what that content is) by default unless you set:
Response.TrySkipIisCustomErrors = true;
Which is what you're seeing.
Additional related info, in MVC5 it seems to act as if that flag is true even if it's false for uncaught exceptions which I don't see in WebForms. As a workaround in Global.asax I'm:
protected void Application_Error()
{
var error = Server.GetLastError();
Server.ClearError();
//code to log error here
var httpException = error as HttpException;
Response.StatusCode = httpException != null ? httpException.GetHttpCode() : (int)HttpStatusCode.InternalServerError;
}
这篇关于如何使用existingResponse ="自动"成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!