質問

I have an asp.net application and I've realized, that if I set ValidateRequest to false, always a standard error page is displayed.

I've heard, that you can display a custom error page.

But I need to know if I can catch the error and display it (after postback) on the current page, that is being displayed.

Is there any way to do this?

役に立ちましたか?

解決

I've found the following article:

http://blogs.msdn.com/b/kaevans/archive/2003/07/07/9791.aspx

The last point of the article (Overriding the OnError Method), describes how to display an error on the current page.

The OnError method has to be overwritten and the error StatusCode has to be set to 200.

protected override void OnError(EventArgs e)
{
  System.Exception oops = Server.GetLastError();

  if(oops.GetBaseException() is System.Web.HttpRequestValidationException )
  {
    System.Diagnostics.Debug.Assert(false);
    Response.Write(oops.ToString());
    Response.StatusCode = 200;
    Response.End();        
  }       
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top