ASP.NET MVC DotNetOpenAuth get ReturnURL after authentication?

When I call my authenticator, I pass the return URL 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 keep this during a call?

Are people storing the local return url in the session? Below is this method.

    [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");
    }
+3
source share
1 answer

I understood:

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

All Articles