登录后注销代码是什么 [英] What the log out code after login
问题描述
当我单击注销按钮时,我想清除所有会话,并且不重新登录就不要进入另一个页面.我已经使用了链接按钮,代码为:
''文件夹内销售示例
When I click the logout button I want to clear all of the session and not to go to another page without logging in again. I already use a link button and the code is:
''example inside folder sale
Session.Clear()
Response.Redirect("Default.aspx")
default.aspx页面在Sale文件夹之外.
产生的错误是:
请求网址:/mywebsite/sale/Default.aspx
我希望从另一页面注销后,全部进入Default.aspx页面.
我希望有人可以帮助我.....; P
The default.aspx page is outside the folder Sale.
The resulting error is:
Request URL :/mywebsite/sale/Default.aspx
I want, after log out from the other page, all to go to Default.aspx page.
I hope somebody can help me..... ;P
推荐答案
用户注销后,清除会话并重定向到sale/Default.aspx.
Response.Redirect("/sale/Default.aspx")
在页面的页面加载事件中,检查会话是否不为null.如果会话为空,则将用户重定向到/sale/Default.aspx页.
When user logs out clear the session and redirect to sale/Default.aspx.
Response.Redirect("/sale/Default.aspx")
In the page load event of the page check for the session not null. If the session is empty then redirect the user to /sale/Default.aspx page.
一个简单的代码即可清除会话+表单身份验证..
A simple bit of code to clear the session + forms authentication would be..
Session.Abandon();
FormsAuthentication.SignOut();
然后,看看Sandeep的技巧.
注销后浏览器后退按钮问题 [
Then, have a look at this tip from Sandeep.
Browser back button issue after logout[^]
You need to disable the ''back'' button behaviour available for cached pages
您需要注销用户并清除授权cookie.
试试:
You need to log the user out, and clear the authorization cookie.
Try:
FormsAuthentication.SignOut();
Session.Abandon();
// Clear the authentication cookie
HttpCookie c = new HttpCookie(FormsAuthentication.FormsCookieName, "");
c.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(c);
// Clear session cookie - shouldn't be needed, but hey-ho.
c = new HttpCookie("ASP.NET_SessionId", "");
c.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(c);
FormsAuthentication.RedirectToLoginPage();
或在VB中:
or, in VB:
FormsAuthentication.SignOut()
Session.Abandon()
' Clear the authentication cookie
Dim c As New HttpCookie(FormsAuthentication.FormsCookieName, "")
c.Expires = DateTime.Now.AddYears(-1)
Response.Cookies.Add(c)
' Clear session cookie - shouldn't be needed, but hey-ho.
c = New HttpCookie("ASP.NET_SessionId", "")
c.Expires = DateTime.Now.AddYears(-1)
Response.Cookies.Add(c)
FormsAuthentication.RedirectToLoginPage()
这篇关于登录后注销代码是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!