我正在尝试将用户在用户名文本框中输入的内容作为 cookie 保存,然后在后续访问时让登录表单自动使用 cookie 值填充文本框。我究竟做错了什么?
这会将用户名保存为 cookie 值,但是当返回登录页面时,cookie 值似乎返回为 null。
我目前有:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim UserName As TextBox = DirectCast(LoginUser.FindControl("UserName"), TextBox)
If User.Identity.IsAuthenticated Then
Response.Redirect("~/media")
End If
Dim UserNameCookie As New HttpCookie("User_Name")
UserNameCookie.Secure = True
UserNameCookie.HttpOnly = True
UserNameCookie.Expires = DateTime.Today.AddDays(7)
UserNameCookie.Value = UserName.Text
Response.Cookies.Add(UserNameCookie)
If Request.Cookies("UserName") IsNot Nothing Then
UserName.Text = Request.Cookies("UserName").Value.ToString()
End If
End Sub