在HTTP中(使用HTTP4.0),我需要返回一个HTTP500结果代码和一个空页面。以下是我尝试过的方法:
Response.StatusCode = (int) HttpStatusCode.InternalServerError;
return new EmptyResult();
Response.StatusCode = (int) HttpStatusCode.InternalServerError;
return Content("");
return new HttpStatusCodeResult(500);但是它总是返回一个页面(html),类似于这个(带有500个) https://i.stack.imgur.com/fKI9C.png。
这真的可行吗?
发布于 2019-01-16 09:19:09
从ASP.NET MVC操作中,可以以以下任何一种格式返回结果:https://learn.microsoft.com/en-us/previous-versions/aspnet/dd410269(v=vs.98)

但是,如果您想返回状态代码并显示它,只需创建一个视图并将状态发送到它并相应地操作:
主计长:
public ActionResult Index()
{
return View("~/Views/Test.cshtml", HttpStatusCode.InternalServerError);
}查看:
@{ Layout = null; }
<h3>@Model</h3>发布于 2019-01-19 07:52:18
我真的可以在全球的Application_Error上做这个
protected void Application_Error(object sender, EventArgs e)
{
Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
Response.Write(string.Empty);
Response.End();
}
}https://stackoverflow.com/questions/54209391
复制相似问题