曲奇重定向到ACS和背部后在极少数情况下空 [英] Cookie is null in rare cases after redirecting to ACS and back

查看:201
本文介绍了曲奇重定向到ACS和背部后在极少数情况下空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站上,有一个登记表。已经填补了这一在后,用户被重定向到的Azure ACS才能登录。经登录后,用户被重定向到我的网站,是要注册并登录

On my website, there is a registration form. After having filled this in, the user gets redirected to Azure ACS in order to log in. After having logged in, the user gets redirected back to my website and is to be registered and logged in.

该登记表是由一个JavaScript提交。用户已填充在通过在RegisterController的RedirectToProvider方法和用户保存到cookie中的信息被重定向到ACS。当用户被重定向到来自ACS的网站时,Cookie,然后由在RegisterController的RegisterUser方法读取。现在的问题是:这个工程的95%的时间。的5%的时间中,当用户回来的cookie是空。我一直无法跟踪这个原因,如果有,我可能已经监督任何已知问题或某事很纳闷。形式code是这样的:

The registration form is submitted by a JavaScript. The information that the user has filled in is saved to a cookie by the RedirectToProvider method in the RegisterController and the user is redirected to ACS. When the user has been redirected back to the website from ACS, the cookie is then read by the RegisterUser method in the RegisterController. The problem is: this works 95% of the time. 5% of the time, the cookie is null when the user comes back. I have been unable to track the cause of this and am wondering if there are any known issues or something that I may have overseen. The form code looks like this:

@using (Html.BeginForm("RedirectToProvider", "Register", FormMethod.Post, new { id = "registerForm" }))

    ... various fields...

    <input type="button" class="btn" id="registerSubmitButton" value="Register" onclick="RegisterRedirect()" />
}

这是提交表单的RegisterRedirect()JavaScript的(与功能无关离开了这里):

The RegisterRedirect() JavaScript that submits the form (with irrelevant functionality left out here):

var RegisterRedirect = function () {
    $("#registerForm").valid();
    $("#registerForm").submit();
}

在RegisterController的RedirectToProvider方法:

The RedirectToProvider method in the RegisterController:

[AllowAnonymous]
[HttpPost]
public ActionResult RedirectToProvider(RegisterViewModel viewModel)
{
    if (ModelState.IsValid)
    {
        var providerUrl = viewModel.SelectedProviderUrl;
        viewModel.SelectedProviderUrl = "";

        var json = JsonConvert.SerializeObject(viewModel);

        try
        {
            var cookie = new HttpCookie("RegisterViewModel", json)
                {
                    Expires = DateTime.Now.AddMinutes(10)
                };
            ControllerContext.HttpContext.Response.Cookies.Add(cookie);
        }
        catch (FormatException)
        {
            return RedirectToAction("Index", "Error", new { reason = "Cookie saving error." });
        }
        return Redirect(providerUrl);
    }
    return RedirectToAction("Index", "Error", new { reason = "Invalid data. Try again." });
}

用户被重定向到ACS,并选择与登录,如Gmail。 ACS叫回我ClaimsAuthenticationManager(在web.config中配置)。随后,被调用的方法回(ACS中配置)被称为,进而调用应该读取cookie的方法RegisterUser:

The user is redirected to ACS and chooses to log in with, for example, Gmail. ACS calls back to my ClaimsAuthenticationManager (configured in web.config). Afterwards, the method to be called back to (configured in ACS) is called and in turn calls the RegisterUser method that is supposed to read the cookie:

[Authorize]
public ActionResult RegisterUser(User user){
    var cookie = ControllerContext.HttpContext.Request.Cookies["RegisterViewModel"];
    if (cookie != null){
        ... registers the user...
    }
}

的95%的时间,则cookie不为空。的5%的时间,一些失败,该cookie为空。的失败率较高时第一构建网站的天青模拟器刚刚开始后和低级以后。我已阅读,它可能有一些做与会议。有谁看到一个明显的错误,或者有什么建议?在此先感谢您的帮助!

95% of the time, the cookie is not null. 5% of the time, something fails and the cookie is null. The fail rate is higher during the first builds of the website after the Azure Emulator has just started, and lower later on. I have read that it could have something to do with sessions. Does anyone see an obvious error or have any advice? Thanks in advance for any help!

推荐答案

我认为问题是由于事实,你有时会重定向到cookie的创建缺少一个不同的Web角色实例。

I think that the problem is due to the fact that you sometimes get redirected to a different web role instance where the cookie you created is missing.

这篇关于曲奇重定向到ACS和背部后在极少数情况下空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆