cookie名称在cookie值内重复

时间:2017-07-30 12:10:10

标签: asp.net angularjs cookies

我在我的ASP.Net响应中写了一些值作为cookie来托管我的AngularJS应用程序。然后我需要使用AJS应用程序中的那些cookie值。

天冬氨酸:

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack == false)
    {
        var accountNumber = Request["AccountNumber"] ?? "";
        AddCookie("AccountNumber", accountNumber);

        var email = Request["Email"] ?? "";
        AddCookie("Email", email);
    }
}
private void AddCookie(string cookieName, string cookieValue)
{
    var cookie = new HttpCookie(cookieName);
    cookie.Values.Add(cookieName, cookieValue);
    cookie.Expires = DateTime.Now.AddDays(1);
    Response.Cookies.Add(cookie);
}

在AddCookie函数中创建cookie时调试输出:



?cookieValue
"moo"
?cookie
{System.Web.HttpCookie}
    Domain: null
    Expires: {2017/08/01 8:32:59 AM}
    HasKeys: true
    HttpOnly: false
    Name: "Email"
    Path: "/"
    Secure: false
    Shareable: false
    Value: "Email=moo"
    Values: {Email=moo}




然后在Angular中:

function myController($log, $stateParams, $cookies) {
    var vm = this;
    vm.accNo = '';

    vm.accNo = $cookies.get('AccountNumber');
    $log.log(vm.accNo);

    vm.email = $cookies.get('Email');
    $log.log(vm.email);
}

日志的输出显示cookie的值包含名称,因此具有value == 123 AccountNumber值为AccountNumber=123的整数。AccountNumber=123

见Fiddler的回复,这证实了这一点:

响应发送了83个字节的Cookie数据:

  

Set-Cookie:AccountNumber = AccountNumber = sfsdfsfs;期满=星期一,   2017年7月31日11:48:08 GMT;路径= /

响应发送了64个字节的Cookie数据:

  

Set-Cookie:Email = Email = sdfsf; expires =周一,31-Jul-2017 11:48:08 GMT;   路径= /

这是一个ASP.Net怪癖还是我在这里做错了什么? 我希望Cookie为AccountNumber=AccountNumer=123而不是select * from some_table where my_column in (select /* distinct? */ my_column from some_table_2)

0 个答案:

没有答案