会话状态下的asp.net c# [英] asp.net c# in session state
本文介绍了会话状态下的asp.net c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在登录页面(login.aspx.cs)中有如下代码
i have the code in login page(login.aspx.cs) as follows
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class login : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
if (txtusername.Text == "ravi" && txtpassword.Text == "reddy")
{
Session["PassWord"] = txtpassword.Text;
Session.Timeout = 1;
Response.Redirect("checkpassword.aspx");
}
else
Response.Write("wrong details");
}
}
并且我在password.aspx.cs中有代码
and and i have the code in password.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class checkpassword : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["PassWord"] == null)
{
Response.Redirect("login.aspx");
}
else
lblstatus.Text = Session["PassWord"].ToString();
}
}
我们想要输出,因为我登录到登录页面后,它在一分钟后刷新了页面,输出显示对不起会话,因此reddy在password.aspx中显示为lable(在浏览器中打开).我需要执行此操作,同时将其重定向到login.aspx页plz help
we want the output as after i login into the loginpage it shows reddy as a lable in password.aspx(it is open in browser) after one mintute time i refresh the page the output was sorry session over . i need this what i do and at the same time it redirect to login.aspx page plz help
推荐答案
不要在ASP.net中使用手动身份验证,除非您有一个很好的理由.查看成员资格和角色功能并使用它们.
如果要检查会话到期和自动重定向,则需要一个小的AJAX脚本来调用服务器端脚本,该脚本类似于
Don''t use manual authentication in ASP.net unless you have a really good reason to. Look at the Membership and Roles features and use them.
If you want to check for session expiry and auto-redirect then you need a little AJAX script that calls a server-side script that looks something like
Response.Write(null == Session["PassWord"] ? "expired" : "valid");
...,然后检查结果,并在必要时重定向到登录页面.
... and then checks the result and redirects to a login page if necessary.
这篇关于会话状态下的asp.net c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文