开发者

Cookies Not Being Added

开发者 https://www.devze.com 2023-03-16 00:33 出处:网络
On the login page I made, this is开发者_开发知识库 part of the code behind for the submit button.

On the login page I made, this is开发者_开发知识库 part of the code behind for the submit button.

        Dim aCookie As New HttpCookie("userInfo")
        aCookie.Values("user") = Me.usr.Text
        aCookie.Values("last") = Now.ToString()
        If Me.remember.Checked() Then
            aCookie.Expires = DateTime.Now.AddDays(3650)
        Else
            aCookie.Expires = DateTime.Now.AddHours(1)
        End If
        Response.Cookies.Add(aCookie)
        'Response.Redirect("~/Default.aspx")
        testBox.Text = Response.Cookies("userInfo")("user").ToString()

For some reason, when it gets to the last line, it throws an error:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.


On your first line you call the cookie userInfo and on the last line you are referencing a cookie named loginInfo, assuming you are trying to access the cookie you just created that's your problem.


Try

 testBox.Text = Response.Cookies("userInfo")("user").ToString()
0

精彩评论

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

关注公众号