开发者

FormsAuthentication.RedirectFromLoginPage does not return me to orignal URL

I reach my login page with the parameter "returnUrl" set to the URL I was on. Then, I login via OpenID (DotNetOpenAuth), and call FormsAuthentication.RedirectFromLoginPage(). The login is successful, however I am not returned to the origina开发者_开发百科l page I was on.

I'm having the same problem on logout - when I log out I don't remain on the same page, even though the logout link contains the correct "returnUrl" parameter.

What am I doing wrong?

Here is the code snippet. I am returning EmptyResult() after the call to RedirectFromLoginPage, because I don't really know what to do (see this related question)

using (var relayingParty = new OpenIdRelyingParty())
{
    var response = relayingParty.GetResponse();

    if (response == null)
    {
        // Stage 2: user submitting Identifier
        var openId = Request.Form["openId"];
        relayingParty.CreateRequest(openId).RedirectToProvider();

        throw new Exception("Never gets here");
    }

    // Stage 3: OpenID Provider sending assertion response
    switch (response.Status)
    {
        case AuthenticationStatus.Authenticated:
            var claimedIdentifier = response.ClaimedIdentifier;
            var user = _userRepository.FindByOpenId(claimedIdentifier);
            if (user != null)
            {
                // login
                FormsAuthentication.RedirectFromLoginPage(user.Id.ToString(), false);
                return new EmptyResult();

                // TODO - https://stackoverflow.com/questions/1991710/understanding-redirections-in-asp-net-mvc
                // throw new Exception("Should never get here");
            }
        ...


This is a shot in the dark but I recently experienced some weirdness with login redirects because the anonymous user did not have rights to my scripts folder. This caused the redirecturl to point to a jquery script because that was the last address the user attempted to access without success.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜