我用设计视图制作了一个简单的Web表单,并在代码后台上放置了两个方法:Page_Load
和Page_PreRender
,如下所示:
public partial class SamplePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.ClearContent();
Response.ClearHeaders();
Response.StatusCode = (int)HttpStatusCode.NotFound;
Respons.Write("Not Found");
Context.ApplicationInstance.CompleteRequest();
}
protected void Page_PreRender(object sender, EventArgs e) // Why does this event get called? Should not the CompleteReqeust()
{ // cause the page to jump directly to the end of events pipeline?
throw new NotImplementedException();
}
}
此外,我已经阅读了许多关于
Response.End()
被称为“丑陋”、“危险”等的问答,甚至是在MSDN网站上。但是这让我感到困惑,如果如此的话,为什么Response.Redirect(string)
仍然在内部使用Response.End()
呢?