我有一个让我保持登录的复选框,所以我使用 cookie 来实现它,但我的问题是我有 2 个要注销的链接,当我点击每个链接时,我没有被重定向到登录页面,因为在登录页面的负载上,我正在测试 cookie 是否已满且始终已满.. 因为注销时我无法清除 cookie... 我尝试从后端调用一个函数来清除cookie,但它没有触发,所以你能帮帮我吗?
Protected Sub btn_login_Click(sender As Object, e As System.EventArgs) Handles btn_login.Click
If Session("valid") Then
If (loginkeeping.Checked = True) Then
Dim mycookie As New HttpCookie("LoginDetail")
Dim username As TextBox = Page.FindControl("username_txtt")
Dim password As TextBox = Page.FindControl("passwordsignup")
mycookie.Values("Username") = username.Text.Trim()
mycookie.Values("Password") = password.Text.Trim()
'mycookie.Expires = System.DateTime.Now.AddDays(1)
Response.Cookies.Add(mycookie)
End If
Response.Redirect("Insert_Content.aspx")
End If
End Sub
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not (Response.Cookies("LoginDetail") Is Nothing) Then
Response.Redirect("Insert_Content.aspx")
End If
End Sub
ASP.NET:
<ul id="nav" class="fl">
<li class="v-sep">
<asp:HyperLink ID="logUser" runat="server" class="round button dark menu-user image-left"></asp:HyperLink>
<ul>
<li><asp:HyperLink ID="Myprofile" NavigateUrl="~/Profile.aspx" runat="server">My Profile</asp:HyperLink>
<li><asp:HyperLink ID="changePAss" NavigateUrl="~/Change_Password.aspx" runat="server">Change Password</asp:HyperLink></li>
<li><asp:HyperLink ID="logout" NavigateUrl="~/LOGIN.aspx" runat="server" onClick="logoutt">Log out</asp:HyperLink></li>
</ul>
</li>
<li><a href="LOGIN.aspx" runat="server" class="round button dark menu-logoff image-left" onClick="logoutt">Log out</a></li>
</ul> <!-- end nav -->
Public Sub logoutt()
Dim CookieName As HttpCookie = Request.Cookies("username")
CookieName.Expires.AddMilliseconds(1)
CookieName.Value = Nothing
Response.Cookies.Add(CookieName)
End Sub