[英]ASP.NET MVC DotNetOpenAuth get ReturnURL after Authenticate?
當我調用我的身份驗證時,我將從查詢字符串傳遞返回URL。 當Open Id提供程序重定向回相同的Action Result時,Return Url參數為null。 在電話會議中堅持這個的最佳方法是什么?
人們是否在會話中存儲了本地Return Url? 以下是有問題的方法。
[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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.