简体   繁体   English

EndResponse是真正的response.redirect在try catch中

[英]EndResponse is true response.redirect in try catch

I don't want the thread abort exception when i use response.redirect method inside try catch block . 当我在try catch块中使用response.redirect方法时,我不希望线程中止异常。 I give end response is true. 我给最终回应是真的。 Is there any possible way instead of throws thread exception. 有没有什么可能的方法可以代替抛出线程异常。 The page is redirected the login page. 该页面被重定向到登录页面。

This is my code, 这是我的代码,

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

As linked here 作为链接在这里

you need to pass false not true in 您需要传递false而不是true

Response.Redirect("login.aspx?fromLnkPg=1", false);

followed by 其次是

Context.ApplicationInstance.CompleteRequest();

You could do 你可以做

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");
}

You may want to use 您可能要使用

Response.IsClientConnected

So 所以

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

try follwing 尝试跟随

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

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

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