无法将请求传输到所需的ASP.NET错误页面 [英] Cannot Transfer request to Desired ASP.NET Error Page

查看:67
本文介绍了无法将请求传输到所需的ASP.NET错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Page_Load()部分中,我检查有效输入&如果它们无效,我会将请求转移到自定义错误页面。

In the Page_Load() section, I check for valid inputs & incase they are invalid, I transfer the request to a custom error page.

在这样做的同时,抛出ThreadAbortException,该异常被我的catch块捕获,但是asp.net传输对未知异常页面的请求。
我在做什么错?当我转移到错误页面时,我不希望ThreadAbortException出现。
例如:

While doing so, a ThreadAbortException is thrown which is caught by my catch block but asp.net transfers the request to unknown exception page. What am I doing wrong? I dont want the ThreadAbortException to come when I transfer to the error page. eg:

     protected void Page_Load(object sender, EventArgs e)
  {

    try
    {
                    if (String.IsNullOrEmpty(szProductName))
                      {
                        //Product name not given. Hence cant process further.
                        Server.Transfer(Constants.ERROR_WRONG_INPUTS_ASPX);
                      }
                    else
                        {
                          //Do something.....
                        }
    }
    catch(Exception Ex)
    {

    }

  }

As解决方法,我现在使用:

As a workaround, I now use:

Response.Redirect(Constants.ERROR_WRONG_INPUTS_ASPX, false);

代替Server.Transfer,即我允许进程在后台继续进行,这要求我检查有效性和然后只执行剩余的代码。

instead of Server.Transfer i.e. I allow the process to continue in the background which made required I check for validity & then only executed the remaining code.

我的问题类似于:,但似乎未得到响应。

My problem is similar to : Exception Handling Application Block Exception Handler running in ASP.NET cannot call Response.End() but it seems it was not answered.

推荐答案

Response.Redirect引发ThreadAbortException以中止当前页面并将控制权转移到新页面。添加错误的参数已解决此问题,因为它告诉Response.Redirect在转移控件之前完成当前页面上的处理。

Response.Redirect throws the ThreadAbortException to abort the current page and transfer control to the new page. Adding the false parameter "fixed" this problem because it tells Response.Redirect to complete processing on the current page before transfering control.

我相信,尽管您需要查看自己的申请流程。由于输入错误而将页面转移到错误页面似乎对我来说是一种处理输入验证的过于复杂的方法。我认为您最好通过显示消息的回发,或者在页面发布之前使用javascript进行一些验证。

I believe though you need to look at your application flow. Having a page transfer to an error page because of input errors seems like an overly complicated way to handle input validation to me. I think you are better off with a postback that displays messages, or doing some validation in javascript before the page is posted.

这篇关于无法将请求传输到所需的ASP.NET错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆