注销后,asp.net无法记住用户名和密码

时间:2014-11-20 17:43:16

标签: asp.net vb.net

我在VS2013中使用asp.net loggin控件,我正在使用asp成员资格

登录代码是

 <asp:Login ID="Login1" runat="server" BackColor="#EFF3FB" BorderColor="#B5C7DE" BorderPadding="2" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" Height="186px" Width="438px" RememberMeSet="True" EnableViewState="true">
        <InstructionTextStyle Font-Italic="True" ForeColor="Black" />
        <LoginButtonStyle BackColor="White" BorderColor="#507CD1" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" />
        <TextBoxStyle Font-Size="0.8em" />
        <TitleTextStyle BackColor="#1B4D82" Font-Bold="True" Font-Size="0.9em" ForeColor="White" />
    </asp:Login>

我的登录页面后面的代码是:

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim username As String = HttpContext.Current.User.Identity.Name

       If Not username = Nothing And User.Identity.IsAuthenticated = True Then

            Server.Transfer("Home1.aspx")


      End If


     End Sub

身份验证是我的web.config

  <authentication mode="Forms">
  <forms name=".ASPXFORMSAUTH" loginUrl="abc/def/login.aspx" defaultUrl="abc/def/login.aspx" timeout="60" cookieless="UseCookies"/>   
  </authentication>

我也找到了一些东西 http://blogs.msdn.com/b/friis/archive/2010/08/18/remember-me-checkbox-does-not-work-with-forms-authentication.aspx

我将其添加到我的登录页面

  Protected Sub OnLoggedIn(ByVal sender As Object, ByVal e As EventArgs)

    If Login1.RememberMeSet = True Then

        'clear any other tickets that are already in the response
        Response.Cookies.Clear()
        'set the new expiry date - to thirty days from now
        Dim expiryDate As DateTime = DateTime.Now.AddDays(30)
        'create a new forms auth ticket
        Dim ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket(2,            Login1.UserName, DateTime.Now, expiryDate, True, String.Empty)
        'encrypt the ticket
        Dim encryptedTicket As String = FormsAuthentication.Encrypt(ticket)
        'create a new authentication cookie - and set its expiration date
        Dim authenticationCookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
        authenticationCookie.Expires = ticket.Expiration
        'add the cookie to the response.
        Response.Cookies.Add(authenticationCookie)
    End If
End Sub

但是,点击退出后,用户名和密码都没有保存。

我想知道如何解决这个问题?谢谢你的建议!

0 个答案:

没有答案