无法使用angularJS&&amp ;;读取cookie。的WebAPI

时间:2015-02-05 12:14:59

标签: javascript angularjs cookies asp.net-web-api

我试图使用angularJS和webAPI创建注册函数 注册后,API应该设置一个cookie。但是,当我重新加载页面时,没有cookie!我不知道问题是什么!!!!

这就是我设置cookie的方式

 public HttpResponseMessage register(User UserToRegister)
    {
        UserToRegister.UserID = Guid.NewGuid();
        YanceySiteDBEntities db = new YanceySiteDBEntities();
        db.Users.Add(UserToRegister);
        db.SaveChanges();

        HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, UserToRegister);
        var cookie = new CookieHeaderValue("useremail", UserToRegister.UserEmail);
        cookie.Expires = DateTimeOffset.Now.AddDays(1);
        cookie.Domain = Request.RequestUri.Host;
        cookie.Path = "/";
        response.Headers.AddCookies(new CookieHeaderValue[] { cookie });

        return response;
    }

这就是我读cookie的方式。

 public bool CheckIfLogIn()
    {
        bool LogedIn = false;
        CookieHeaderValue cookie = Request.Headers.GetCookies("useremail").FirstOrDefault();
        if (cookie != null) LogedIn = true;

        return LogedIn;
    }

希望有人可以帮助我,提前致谢!

0 个答案:

没有答案