C# 重定向抛出错误
我的回复有问题。重定向呼叫 错误: System.Threading.ThreadAbortException:正在中止线程。在 位于的System.Threading.Thread.AbortInternal() 位于的System.Threading.Thread.Abort(对象状态信息) 位于的System.Web.HttpResponse.End() 位于的System.Web.HttpResponse.Redirect(字符串url,布尔值endResponse) System.Web.HttpResponse.Redirect(字符串url)位于 中的Web.AdminUser.LoginHandler.OpenIdLogin() c:\Builds\15\Digital\main\Sources\Web\Public\LoginHandler.aspx.cs:line 113 重定向发生在C# 重定向抛出错误,c#,asp.net,C#,Asp.net,我的回复有问题。重定向呼叫 错误: System.Threading.ThreadAbortException:正在中止线程。在 位于的System.Threading.Thread.AbortInternal() 位于的System.Threading.Thread.Abort(对象状态信息) 位于的System.Web.HttpResponse.End() 位于的System.Web.HttpResponse.Redirect(字符串url,布尔值endResponse) System.We
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();
这应该可以避免
线程中止异常
,但仍然可以完成请求。您可以说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);
将始终运行。当您希望新的潜在客户停止执行时,它将保存新的潜在客户。您应该使用下面的
Response.Redirect("URL", false);
如果看不到实际的代码,就很难找出哪里出了问题LoginHandler.aspx.cs中的您是什么样子的,特别是在第113行的区域?好吧,这不会发生,将终止或继续的是响应流本身,而不是执行的代码,因此上面的代码不会出现“Prospect.Save()”方法(如果发生重定向)。