开发者

ASP.NET MVC DotNetOpenAuth get ReturnURL after Authenticate?

When I call my authenticate, I am passing the Return Url from from the Query String. When the Open Id provider redirects back to the same Action Result, the Return Url parameter is null. What is the best way to persist this across the call?

Are people storing the local Return Url in the session? Below is the method in question.

    [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");
    }


I figured it out:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜