且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

会话超时和登录

更新时间:2023-12-04 18:33:58

这是你会被重定向登录后到登录页面非常明显的事情
我向您展示几种方法来实现这一目标...

 会话[将把userid]

现在,当用户处于闲置状态,现在20分钟的purchase.aspx :(
 因此,当他重新加载或点击您的导航任何页面上,将工作像这样

在页面加载使用此code


 如果(会话[将把userid]!= NULL)
           {
//做的东西,因为你会不为空
}
其他
{
会议[previouspage] =页面名称;
的Response.Redirect(login.aspx的);
}

在登录页使用该会话重定向到previous页


现在***,如果你不想会话加载到内存中的另一种方式实现这一目标的方式是


  

查询字符串


块引用>
 如果(会话[将把userid]!= NULL)
           {
//做的东西,因为你会不为空
}
其他
{的Response.Redirect(?login.aspx的previousPage =+您的网页名称);
}

在登录页你将有查询字符串previous页

的Request.QueryString [previousPage]在这您previous页将被定义

因此​​,在短期,你将在这个previous页面,您可以重定向到成功登录后页面

我希望这会帮助你:)

If user has logged in and opened any page in my website and does nothing for 20 mins. Now if he selects any thing from menu or clicks any button he is redirected to login page. Now I have problem after login. The user is redirected to main page only where as I want to redirect user to the page where he wanted to go before when he clicked the menu item.

Thanks for help in advance..

This is very obvious thing that you are redirected to login page after login I am showing you several ways to achieve this...

session["userid"]

Now when user is idle for 20 mins now at purchase.aspx :( So when he reload or click on any page from your navigation it will work like this

Use this code in a page load


if (Session["userid"] != null)
           {
// do stuff because your session is not null
}
else
{
session["previouspage"]="your page name";
response.redirect("login.aspx");
}

and at login page use this session to redirect to the previous page


Best way now if you don't want to load the session into memory another way to achieve this is

query string

if (Session["userid"] != null)
           {
// do stuff because your session is not null
}
else
{

response.redirect("login.aspx?PreviousPage="+Your page name);
}

and at login page you will have a previous page with query string

request.querystring["PreviousPage"] in this your previous page will be defined

So in short you will have a previous page in this and you can redirect to that page after successful login

I hope this will help you :)