简体   繁体   中英

How to Redirect to Login page while click on logout

I am developing a application in asp .net 4.0.

Here when I am logged in to my application, go to inner pages, say "Manage Role" and copy the link and click on Logout button it displays my login page. Now i paste that link in another tab and expect it to display me the login page but it does not happen, it shows me Manage Role page.

So please give me some solution, how can i show login page in this case?

您必须使用会话变量来检查用户是否已登录,然后在我们的每个页面中..在页面加载事件中,您必须检查该会话用户变量是否为null,如果为null,则将其重定向到登录页面

Try using Session Destroy function available in ASP.Net if you are using C#

try:

Session.Abandon();

If you want to remove a specific item from the session use (MSDN):

Session.Remove("YourItem");

EDIT: If you just want to clear a value you can do:

Session["YourItem"] = null;

If you want to clear all keys do:

Session.Clear();

And Then Check for Session Value on every page you want to restrict only with Session Access(for Logged In User).

In Your page "Manage Role",In Your Page load, Check that user info is available or not in the session. and When you Click on log out button,First Remove User Information from Session and then Redirect it Login Page.

First Remove All Session on logout button click event

 Session.Abandon();
    Session["SessionName"] = null;
    Session.Clear();

Then Write Code in Global.asax File

  Void Application_Error(object sender,EventArgs e)
    {
         Response.Redirect("LogIn.aspx");
         or
         Server.Transfer("LogIn.aspx");
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM