gpt4 book ai didi

asp.net-mvc - ASP.NET MVC DotNetOpenAuth 在身份验证后获取 ReturnURL?

转载 作者:行者123 更新时间:2023-12-03 16:44:26 28 4
gpt4 key购买 nike

当我调用我的身份验证时,我从查询字符串中传递返回 Url。当 Open Id 提供程序重定向回相同的 Action Result 时,Return Url 参数为 null。在整个通话过程中坚持这一点的最佳方式是什么?

人们是否将本地返回 Url 存储在 session 中?以下是有问题的方法。

    [ValidateInput(false)]
public ActionResult Authenticate(string returnUrl)
{
openId = new OpenIdRelyingParty();

IAuthenticationResponse response = openId.GetResponse();

if (response == null)
{
Identifier id;
if (Identifier.TryParse(Request.Form["openid_identifier"], out id))
{
try
{
// at this point we have a return Url
return openId.CreateRequest(id).RedirectingResponse.AsActionResult();
}
catch (ProtocolException pex)
{
ModelState.AddModelError("", pex.Message);
return View("LogOn");
}
}
else
{
ModelState.AddModelError("", "Invalid Identifier");
return View("LogOn");
}

}
else
{
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, true);
// at this point return URL is null

var fetch = response.GetExtension<FetchResponse>();
string email = string.Empty;
if (fetch != null)
email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);

if (!string.IsNullOrEmpty(returnUrl))
{
var test = FormsAuthentication.GetRedirectUrl(User.Identity.Name, false);
var url = AppHelper.GenerateReturnURL(Request, returnUrl);
return Redirect(url);
}
else
{
return RedirectToAction("Index", "Home");
}
case AuthenticationStatus.Canceled:
ModelState.AddModelError("", "Canceled at provider");
return View("LogOn");
case AuthenticationStatus.Failed:
ModelState.AddModelError("", response.Exception.Message);
return View("LogOn");
}
}

return View("LogOn");
}

最佳答案

我想通了:

                        //add returnURL as a callback argument
if (!string.IsNullOrEmpty(returnUrl))
request.AddCallbackArguments("returnUrl", returnUrl);

关于asp.net-mvc - ASP.NET MVC DotNetOpenAuth 在身份验证后获取 ReturnURL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5355498/

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