0
我不知道如何可以使用cookie爲ASP登錄時整登錄似乎被包裝成一個控制(我不能看到ASP代碼內文本框的用戶和密碼的文本框)。ASP登錄保存Cookie的用戶帳戶
登錄的代碼是
<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
If Not IsPostBack Then
'------------------------------get cookies-----------------------
If ((Not (Request.Cookies("UserName")) Is Nothing) _
AndAlso (Not (Request.Cookies("Password")) Is Nothing)) Then
Login1.UserName = Request.Cookies("UserName").Value
'Login1.Password.value = Request.Cookies("Password").Value '----how Can I write this row correctly??
End If
End If
'--------------------check authentication-------------
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>
洛後的代碼在是
Protected Sub OnLoggedIn(ByVal sender As Object, ByVal e As EventArgs)
If Login1.RememberMeSet = True Then
Response.Cookies("UserName").Expires = DateTime.Now.AddDays(30)
Response.Cookies("Password").Expires = DateTime.Now.AddDays(30)
Else
Response.Cookies("UserName").Expires = DateTime.Now.AddDays(-1)
Response.Cookies("Password").Expires = DateTime.Now.AddDays(-1)
End If
Response.Cookies("UserName").Value = Login1.UserName.Trim
Response.Cookies("Password").Value = Login1.Password.Trim
End Sub
我退出後,cookies不會得到保存(即使我檢查記得我)。我想知道如何解決這個問題?通常,我不知道如何在註銷後在登錄窗口中保留密碼。
感謝您的任何建議!
肯定的,但用戶要少保,他只是希望看到的密碼,即使在註銷後填滿,那麼他就可以直接點擊登錄重新登錄 – user3344443 2014-11-22 13:46:11