繁体   English   中英

单击按钮后重定向会引发错误 ASP.NET

[英]Redirecting after click on button throws error ASP.NET

我使用常规按钮将跨度放入按钮中。 我还制作了 onServerClick 函数(用于处理事件)。

<button id="btnCancel" runat="server" class="btn btn-default pull-right" onserverclick="btnCancel_Click"><span class="glyphicon glyphicon-remove text-magenta"></span>Cancel</button> 

这应该是简单的取消按钮,应该退出表单并注意其他内容。 但由于某种原因,C# 函数在重定向时抛出异常。

这是功能:

            try
        {
            Response.Redirect("StartPage.aspx");
        }
        catch (Exception ex)
        {
            NLog.LogManager.GetCurrentClassLogger().Warn("Error happened", ex);
            Response.Redirect("Error.aspx", false);
        }

另外,如果我只是不尝试并捕获块,一切正常。

Response.Redirect抛出一个被您的异常处理程序捕获的ThreadAbortException 任何一个

  • 删除异常处理程序(如果实际代码与您的示例一样简单,则不需要异常处理程序)或
  • Response.Redirect移出异常处理程序或
  • 像这样为ThreadAbortException创建一个专用处理程序:

try
{
    Response.Redirect("StartPage.aspx");
}
catch (ThreadAbortException)
{
  // Exception is expected, do nothing
}
catch (Exception ex)
{
    NLog.LogManager.GetCurrentClassLogger().Warn("Error happened", ex);
    Response.Redirect("Error.aspx", false);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM