响应.重定向抛出错误

本文关键字:错误 出错 重定向 响应 | 更新日期: 2023-09-27 18:13:01

我有一个问题与响应。重定向的电话。

错误:

System.Threading。ThreadAbortException:线程被中止。在System.Threading.Thread.AbortInternal ()System.Threading.Thread。中止(对象状态信息)System.Web.HttpResponse.End ()System.Web.HttpResponse。重定向(字符串url,布尔endResponse)System.Web.HttpResponse。重定向(字符串url)Web.AdminUser.LoginHandler.OpenIdLogin ()c: '主要构建数字' ' 15 ' ' ' Web '公共来源' LoginHandler.aspx.cs:行113

重定向发生在try - catch语句中,我似乎找不到正确的方法来做它。

try
        {
            if (Request.Form.HasKeys())
            {
                Global.Logger.Info(string.Format("OpenIdLogin_Has_Keys"));
                string request = Request.Form.GetValues("token")[0].ToString();
                Rpx rpx = new Rpx("123412341234", "https://login.youwebsite.com/");

                var xml = rpx.AuthInfo(request).InnerXml;
                //lblx.Text = xml.ToString();
                XElement xdoc = XElement.Parse(xml);
                if (xdoc.Element("email") != null)
                    xdoc.Element("email").Value = "";

                int userId = SaveMember(xdoc);
                if (userId > -1)
                {
                    //add the user id to session for later
                    Session["CurrentUserId"] = userId;
                    Session["UserLoggedIn"] = true;
                }
                else
                {
                    Session["UserLoggedIn"] = false;
                }
                articlePath = String.Format(articlePath, Section, Name);
                Response.Redirect(articlePath, false);
            }
        }
        catch (Exception e)
        {
            Global.Logger.Error(e);
            articlePath = String.Format(articlePath, Section, Name);
            Response.Redirect(articlePath, false);
        }

响应.重定向抛出错误

试试这个技巧:

Response.Redirect("...", false);
HttpContext.Current.ApplicationInstance.CompleteRequest(); 

这应该避免ThreadAbortException,但仍然完成请求。

你应该使用下面的

Response.Redirect("URL", false);

你可以输入Response.Redirect(“home.aspx”, false);,它不会停止请求。

,但它将继续执行。所以使用Response.Redirect(“home.aspx”, false);时要小心

如果你传递false,你将不会得到错误,但它不会结束请求

如果我说错了请纠正我。但是像这样的代码
public void Btn_Click() 
{
    if(count == 0)
    {
          Response.Redirect("OutOfStock.aspx", false);
    }
    Prospect.Save(-1, purchaceDate);
}

即使count == 0

Prospect.Save(-1, purchaceDate); 

将始终运行。并在您可能希望它停止执行时保存一个新的前景

相关文章: