【发布时间】:2011-12-13 06:43:37
【问题描述】:
我正在使用会话对用户进行身份验证。我的项目中有 2 个网页。一个是webform,一个是EntryForm.aspx,另一个是log.aspx
在 log.aspx 中我已经完成了
protected void Button1_Click(object sender, EventArgs e)
{
user_login loginu = new user_login();
String uid_db = loginu.login(this.DropDownList1, this.TextBox1, this.TextBox2, this.Label5);
if (uid_db == "invalid")
{
Label5.Visible = true;
Label5.Text = "Invalid Login";
}
else
{
string uname = uid_db.Substring(0, uid_db.IndexOf(",")).Trim();
string[] tokens = uid_db.Split(',');
string dbname = tokens[tokens.Length - 1];
Session["login"] = uname;
Session["db"] = dbname;
Response.Redirect("EntryForm.aspx");
}
}
在user_login 类中,我正在获取存储在数据库中的密码并将其与用户输入的值匹配。如果它找到一个值,我将它重定向到 EntryForm.aspx。我在其中检查会话变量如下
protected void Page_Load(object sender, EventArgs e)
{// CHEK SESSION VARIABLE AND LOAD dropdownlist1 WITH VALUES
if (!IsPostBack)
{
String DB = "";
String AccountID = "";
if (Session["login"] != null && Session["db"] != null)
{
AccountID = Session["login"].ToString();
DB = Session["db"].ToString();
Label9.Text = AccountID;
}
else
{
Response.Redirect("log.aspx");
}
HiddenField1.Value = DB.ToString();
DropDown a = new DropDown();
a.filldropdown1(this.DropDownList1, DB);
}
}
这就是我所做的验证用户的工作。在服务器上我做了以下配置:
我没有在Global.asax 中进行任何设置,web.config 也没有任何设置。我看过很多论坛,其中配置了Global.asax 和web.config。
我想知道在我的项目中我需要做什么才能非常高效地工作。我面临会话超时问题。我在我的服务器上将它设置为 20 分钟,但有时我会突然退出。
请帮助我理解使用会话进行身份验证。
【问题讨论】:
标签: asp.net session windows-server-2008