3
當我登錄時,使用.NET 4和帶有自定義佈局模板的asp.net登錄控件,無論是否選中記住我複選框,控件似乎會創建一個身份驗證Cookie,並讓我登錄,直到我通過單擊退出按鈕明確退出。在登錄狀態下關閉瀏覽器並不會使我註銷。asp:使用LayoutTemplate登錄會創建持久性cookie,無論是否記住我被檢查
有人可以幫助解釋可能是什麼原因造成的?
<asp:Login ID="Login1" runat="server" OnLoggingIn="Login1_LoggingIn" OnLoggedIn="Login1_LoggedIn" OnLoginError="Login1_LoginError">
<LayoutTemplate>
<asp:Panel runat="server" DefaultButton="btnLogin">
<label>Email</label> <div class="required">*</div>
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" Display="Dynamic" ErrorMessage="Required" InitialValue="" SetFocusOnError="true" ValidationGroup="Login" /><br />
<asp:TextBox runat="server" ID="UserName" class="input" ValidationGroup="Login" />
<label>Password</label> <div class="required">*</div>
<asp:RequiredFieldValidator runat="server" ControlToValidate="Password" Display="Dynamic" ErrorMessage="Required" InitialValue="" SetFocusOnError="true" ValidationGroup="Login" /><br />
<asp:TextBox runat="server" ID="Password" TextMode="Password" class="input" style="margin:0 0 6px 0;" ValidationGroup="Login" />
<asp:Checkbox runat="server" ID="RememberMe" Text="Remember me" CssClass="remember-me" />
<asp:LinkButton runat="server" ID="btnLogin" CommandName="Login" Text="Sign In" CssClass="login-button" ValidationGroup="Login" />
</asp:Panel>
</LayoutTemplate>
</asp:Login>
protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
{
string username = Login1.UserName.Trim();
if (IsValid)
{
MembershipUser user1 = Membership.GetUser(username);
if (user1 != null)
{
if (Membership.ValidateUser(user1.UserName, Login1.Password))
{
Login1.UserName = user1.UserName;
}
}
}
protected void Login1_LoggedIn(object sender, EventArgs e)
{
if (Roles.IsUserInRole(Login1.UserName, "Users"))
{
Response.Redirect("users.aspx", true);
}
<authentication mode="Forms">
<forms timeout="129600" name=".AUTHCOOKIE" protection="All" slidingExpiration="true" path="/" requireSSL="false" loginUrl="~/login.aspx" cookieless="UseCookies"/>
</authentication>
感謝您的回覆,但這是行不通的。我在if(Membership.ValidateUser())中添加了RedirectFromLoginPage(),並且在成功登錄後記住我沒有選中我關閉瀏覽器窗口,然後返回到網站,我仍然登錄。這是在我們的測試服務器上,不是本地主機。 – 2014-10-10 15:37:20
你關閉了整個瀏覽器還是關閉了選項卡?因爲我試圖關閉整個瀏覽器和所有實例,並且它對我有用......嗯......讓我看看我是否可以拿出別的東西。 – 2014-10-10 18:42:19
這是我從那裏得到答案,併爲他工作:http://stackoverflow.com/questions/2715873/asp-net-forms-authentication-cookie-not-expiring/2716020#2716020 – 2014-10-10 18:43:37