我想知道是否有可能从MVC控制器返回一个带有内容的错误请求?我能够做到这一点的唯一方法是在throw HttpException这里我不能设置任何内容.试过这种方法,但由于一些奇怪的原因,我总是得到回报.是否有可能做到这一点?
public class SomeController : Controller
{
[HttpPost]
public async Task<HttpResponseMessage> Foo()
{
var response = new HttpResponseMessage(HttpStatusCode.BadRequest);
response.Content = new StringContent("Naughty");
return response;
}
}
Run Code Online (Sandbox Code Playgroud) 文件说
existingResponse="PassThrough"如果存在现有响应,则保持响应不变. http://www.iis.net/configreference/system.webserver/httperrors#005
但是,"现有的反应是否存在"意味着什么呢?
例如,我希望我的customErrors处理程序抑制ASP.NET响应,以便IIS认为响应不存在.我该怎么办?