gpt4 book ai didi

c# - Response.Redirect 抛出错误

转载 作者:太空狗 更新时间:2023-10-30 00:05:48 32 4
gpt4 key购买 nike

我在调用 response.redirect 时遇到问题。

错误:

System.Threading.ThreadAbortException: Thread was being aborted. at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object stateInfo) at System.Web.HttpResponse.End() at System.Web.HttpResponse.Redirect(String url, Boolean endResponse) at System.Web.HttpResponse.Redirect(String url) at Web.AdminUser.LoginHandler.OpenIdLogin() in c:\Builds\15\Digital\main\Sources\Web\Public\LoginHandler.aspx.cs:line 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,但仍会完成请求。

关于c# - Response.Redirect 抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7981755/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com