【问题标题】:EndResponse is true response.redirect in try catchEndResponse 是 true response.redirect 在 try catch
【发布时间】:2013-09-13 09:54:36
【问题描述】:

当我在 try catch 块中使用 response.redirect 方法时,我不希望线程中止异常。我给端的反应是真的。有什么方法可以代替抛出线程异常。该页面被重定向到登录页面。

这是我的代码,

 try
    {
        Response.Redirect("login.aspx?fromLnkPg=1", true);
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message.ToString());
    }

【问题讨论】:

  • 我希望在 response.redirect 方法中结束响应属性为真。请提供任何可能的方式。
  • 那很好。有没有可能的方法...我不想放两个catch块。
  • 您想使用 Redirect 和 true 作为 endResponse 参数值,但您不想有两个 catch 块?那么你所要求的就是不可能的 - 你需要使用错误的两个 catch 块或完全放弃 Response.Redirect 以支持不同的重定向方式。

标签: c# asp.net


【解决方案1】:

链接here

您需要在

中传递false 而不是true
Response.Redirect("login.aspx?fromLnkPg=1", false);

紧随其后

Context.ApplicationInstance.CompleteRequest();

【讨论】:

  • 出于好奇,你为什么需要它是真的?
  • 如果你传递 true 线程将被中止,它会抛出一个异常。除了处理异常的开销之外,这似乎表明您希望在重定向发生后发生一些事情,这是错误的。做你需要做的,然后将请求传递到下一页。
  • 不错的问题 sf,因为我使用 fiddler 调试器。它显示了html输出的页面。页面重定向的位置。如果我给出真实的最终响应。 fiddler 调试器 html header 只有 login.aspx 页面...进程也停止了。
  • 这是正确的功能。重定向正是这样做的,重定向在服务器上。没有理由编写代码以便您可以使用 fiddler,部署时 fiddler 不会在服务器上运行。你看这一切都错了。
【解决方案2】:

你可以的

try
{
    Response.Redirect("login.aspx?fromLnkPg=1", true);
}
catch (Exception ex)
{
    // Removed as not needed due to redirect Response.Write(ex.Message.ToString());
    Response.Redirect("hompage.aspx");
}

你可能想使用

Response.IsClientConnected

所以

bool b = Response.IsClientConnected;
Response.Redirect("login.aspx?fromLnkPg=1", b);

【讨论】:

  • 谢谢,但如果我遇到任何其他异常。它应该被重定向到 home.aspx 页面
  • 感谢 Response.IsClientConnected;价值。但我的 response.redirect 应该是真的。
  • 出现异常时是否要重定向到主页?
【解决方案3】:

尝试关注

try
{
    Response.Redirect("login.aspx?fromLnkPg=1", true);
}
catch (ThreadAbortException) 
{
}
catch (Exception ex)
{
    Response.Redirect("home.aspx");        
}

【讨论】:

  • 对不起..我不知道任何其他方式
猜你喜欢
  • 2010-10-31
  • 1970-01-01
  • 1970-01-01
  • 2013-02-25
  • 2015-08-04
  • 1970-01-01
  • 1970-01-01
  • 2012-05-27
  • 2010-11-07
相关资源
最近更新 更多