无法获得cookie,即

时间:2014-12-16 19:39:17

标签: asp.net asp.net-mvc internet-explorer cookies

我在cookie中存储了一些UserData。它在铬和mozilla中工作正常。但是在IE中它无法获取cookie。我正在使用IE版本10.请帮帮我吗?

在登录表单中:

        Dim Mydtt As String = "my custom data "
        Dim authTicket = New FormsAuthenticationTicket(2, usrid, Date.Now, Date.Now.AddDays(7), True, Mydtt, "/")

        Dim cookie As New HttpCookie("usrlg", FormsAuthentication.Encrypt(authTicket))
        Response.Cookies.Set(cookie)
        Response.Redirect("~/phed/reports")

在会话开始时:

        Dim LastLoginCookie As HttpCookie
        LastLoginCookie = HttpContext.Current.Request.Cookies.Get("usrlg") ' Return Nothing in IE '
        Dim LastLgTicket As FormsAuthenticationTicket = FormsAuthentication.Decrypt(LastLoginCookie.Value)
        Dim Mydtt As String = LastLgTicket.UserData

2 个答案:

答案 0 :(得分:0)

您可能希望在解密之前检查空值。

Dim LastLoginCookie = HttpContext.Current.Request.Cookies("usrlg")

If LastLoginCookie IsNot Nothing Then
   Dim LastLgTicket As FormsAuthenticationTicket = 
      FormsAuthentication.Decrypt(LastLoginCookie.Value)
   Dim Mydtt As String = LastLgTicket.UserData
End If

类似的回答here

答案 1 :(得分:0)

我记得cookie.Secure必须正确设置,例如HTTP为false,HTTPS为true。 您可以使用Request对象自动检测协议:

cookie.Secure = Request.IsSecureConnection;
Response.Cookies.Set(cookie);

希望这有帮助。