关闭登录的网站浏览器,然后第二次登录无需密码 [英] close a logged in web site browser, then no need password to login the 2nd time
问题描述
大家好,我有一个asp.net网站应用程序,使用会员资格进行身份验证,但我有一个问题:
1.当我登录时,
2.并关闭我的网站,
3.键入一个页面的URL(需要登录并可以访问)
但我可以直接到达此页面这次没有登录(在我关闭网站应用程序之后)。
所以如何解决问题plz,这是我的母版页的代码片段:
hi guys, i have a asp.net web site app, use of membership for the authentication, but i have a problem that:
1. when i login,
2.and close my web site,
3.type one page URL (which needed to log in and can be visited)
but i can directly reach this page without login this time(after i closed the web site app).
so how can i solve the problem plz, here is my master page's code snippet:
protected void Page_Load(object sender, EventArgs e)
{
//close browser then logout
//what should be here??may be
//log out then back button not work
Response.Cache.SetNoStore();
}
//works fine here
protected void LoginStatus1_LoggedOut(object sender, EventArgs e)
{
Session.RemoveAll();
Session.Abandon();
Session.Clear();
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
}
尝试了几种方法但失败了..所以,我只是想在关闭后登录我的网站浏览器没有点击退出按钮,提前谢谢!
tried several methods but failed..so, i just want to log in after i close my website browser without click the logout button,thanks in advance!
推荐答案
你需要依靠cookie才能实现这一点。
You need to rely on cookie for achieving this.
我认为你需要在浏览器出口处清除会话。
你可以参考这个 [ ^ ]链接和这个 [ ^ ]。
希望这对你有所帮助。
此致,
RK
Hi,
I think you need to clear the session at browser exit.
You can refer this[^] link and this [^].
Hope this helps you a bit.
Regards,
RK
使用Cookies保存用户名和密码剑到浏览器
Use Cookies to save User name and password to browser
Protected Sub Login_Click(ByVal sender As Object, ByVal e As EventArgs)
If chkRememberMe.Checked 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 = txtUserName.Text.Trim
Response.Cookies("Password").Value = txtPassword.Text.Trim
End Sub
呼叫页面加载
Call on Page Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Cookies["UserName"] != null && Request.Cookies["Password"] != null)
{
txtUserName.Text = Request.Cookies["UserName"].Value;
txtPassword.Attributes["value"] = Request.Cookies["Password"].Value;
}
}
}
这篇关于关闭登录的网站浏览器,然后第二次登录无需密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!