注销按钮无法正常工作 [英] Logout Button is not working properly

查看:91
本文介绍了注销按钮无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个注销页面。当我点击退出按钮时,它会将我重定向到登录页面......但作为浏览器的按下按钮,它会重新打开欢迎页面。我想这样做,如果任何用户点击退出按钮,然后按回按钮它不应该打开欢迎页面。





欢迎页面上的编码如下: -



  public   partial   class 主页:System.Web.UI.Page 
{
protected void Page_Load( object sender,EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
if (!IsPostBack)
{
Label1.Text =( string )会话[ username];
}


}
受保护 void Button1_Click( object sender,EventArgs e)
{
Session.Abandon();
Session.Remove( username);
FormsAuthentication.SignOut();

Response.Redirect( Default.aspx);

}
}

解决方案

你只需要删除你所有的会话已经创建。

每当重定向你想要的页面后,检查会话中是否没有任何值作为它们的值。

这样做之后,你得到的页面点击回来的事件按钮只是检查它们是否是活动会话,如果它们没有任何值重定向到登录页面。



谢谢..


< blockquote>如果您尝试永久解决所有页面的问题,请尝试如下:

首先制作一个基页并覆盖OnPreInit事件并在其中检查会话,如果您使用并且会话不可用或没有然后重定向到登录页面以访问欢迎或任何其他页面。



此基页继承到您需要成功登录的任何页面。

你试试这个解决方案吗?

退出后浏览器后退按钮问题 [ ^ ]

,请参阅..

浏览器返回按钮问题 [ ^ ]


返回的解决方案在ASP.NET中注销后按钮问题
[ ^ ]

,在 CodeProject [ ^ ]对于这个问题,那里有大量有用的链接。


Actaully I have created a logout page. When I click on logout button it redirects me to login page...but as a press back button of browser it reopen welcome page. I want to do that if any user click on log out button and after that press back button it should not open welcome page.


Coding is as follows on welcome page:-

public partial class Home : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        if (!IsPostBack)
        {
            Label1.Text = (string)Session["username"];   
        }
        
       
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Session.Abandon();
        Session.Remove("username");
        FormsAuthentication.SignOut();
        
        Response.Redirect("Default.aspx");

    }
}

解决方案

you just need to remove all the sessions that you've already created.
whenever after redirecting your desired page check whether sessions will have nothing as their values in them.
After doing so, the page you get on click event of back button just check whether their are active sessions, if they are not having any values redirect to the login page.

thanks..


If you try to permanent solution for all pages then try as below:
First make one base page and override OnPreInit event and in them check session as you use and if session is not available or have not value then redirect to login page for access welcome or any other page as you required.

This base page inherits to any page as you required to login successfully.


Do you try this solution?
Browser Back Button Issue After Logout[^]
Or,see..
Browser Back button Issue[^]

Solution to back button problem after logout in ASP.NET
[^]
Or, have a search in CodeProject[^] for this issue,tons of helpful links there.


这篇关于注销按钮无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆