我对response.redirect的电话有个问题。
错误:
System.Threading.ThreadAbortException:线程被中止。在c:\Builds\15\Digital\main\Sources\Web\Public\LoginHandler.aspx.cs:line 113中,System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object stateInfo) at System.Web.HttpResponse.End() at System.Web.HttpResponse.Redirect(String url,Boolean ) at System.Web.HttpResponse.Redirect(String url) at Web.AdminUser.LoginHandler.OpenIdLogin()
重定向发生在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);
}发布于 2011-11-02 14:13:25
尝试使用这种技术:
Response.Redirect("...", false);
HttpContext.Current.ApplicationInstance.CompleteRequest(); 这样可以避免ThreadAbortException,但仍然可以完成请求。
发布于 2011-11-02 14:13:57
您可以说是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);
}即使计数== 0
Prospect.Save(-1, purchaceDate); 永远都会跑。当您期望新的前景停止执行时,它将保存下来。
发布于 2011-11-02 14:14:53
您应该使用下面的
Response.Redirect("URL", false);https://stackoverflow.com/questions/7981755
复制相似问题