开发者

MVC 3 FormsAuthentication RedirectUrl and OpenID

I have one View called SignIn that contains two partial views for authentication. One is for OpenID and the other is for logging in to my site using an internal account.

The Action for the OpenID form goes to an OpenIDSignIn() Action while the other just points to SignIn(). Everything works great except for when a user clicks a link to a view that requires them to be logged on [Authorize] etc..

I see the returnUrl in the QueryString however this value is not available to the current controller action, due to the fact that they will be either be logging in with OpenID or normally, thus caling the 开发者_如何学GoActionResult associated with either of those views.

Just for clarification the returnUrl is the one that gets thrown in there from FormsAuthentication and is used when doing a RedirectFromLoginPage etc..


public ActionResult SignIn(string returnUrl)
    {
        if(!string.IsNullOrEmpty(returnUrl))
        {
            if(UrlUtil.IsLocalUrl(returnUrl))
            {
                Session.Add("ReturnUrl", returnUrl);
            }
            else
            {
                return RedirectToAction("SignIn", "Account");
            }


        }
        return View();
    }

This seems to be a viable workaround. However I hate session variables!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜