Setting Context.Response.StatusCode does not seem to work

允我心安 提交于 2019-12-04 07:35:10
Randolpho

Firebug shows the correct status. Does this mean that if I want the browser to display a message, I have to render it myself? – deverop

Absolutely it does. What the browser does based on an error code received is up to the browser. But you can still provide HTML to go along with the 404. Case in point... take a look at Stack Overflow's 404 page. That error message is entirely hand crafted.

Typically, however, you want to limit the amount of data returned from an error status; the more data you return from an erroneous request, the larger the surface of attack for denial of service.

First Try this:

protected void Page_Load(object sender, EventArgs e)
{
    Response.StatusCode = 404;
    Response.SuppressContent = true;
    HttpContext.Current.ApplicationInstance.CompleteRequest();
}

:)~

I had a similar problem, which occures in IIS 7.0 only. What you could also try is to set

Response.TrySkipIisCustomErrors = true;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!