本帖最后由 迷你卡卡 于 2013-9-30 14:26 编辑
<form id="form1" runat="server">
<div>
用户名:<asp:TextBox ID="txtUsertype" runat="server"></asp:TextBox><br />
密 码:<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox><br />
<asp:Button ID="btnLogin" runat="server" Text="登陆" />
</div>
</form>
这是一个简单的登陆界面,
protected void Button1_Click(object sender, EventArgs e)
{
string usertype = txtUsertype.Text.Trim();
Session["UserType"] = GetUsertype(usertype);
Application.Lock();
switch (Session["UserType"].ToString())
{
case "1":
Application["admin"] = Convert.ToInt32(Application["admin"]) + 1;
break;
case "2":
Application["user"] = Convert.ToInt32(Application["user"]) + 1;
break;
case "3":
Response.Write("<script>alert('非法账户,不能登陆')</script>");
break;
}
Application.UnLock();
Response.Redirect("count.aspx?=usertype" + usertype);
}
private static int GetUsertype(string str)
{
if (str=="admin")
{
return 1;
}
if (str=="user")
{
return 2;
}
else
{
return 3;
}
}
这是他的后台代码,
protected void Page_Load(object sender, EventArgs e)
{
string usertypeCount = Request.QueryString["usertype"].ToString();
if (Application["admin"]!=null)
{
Response.Write("<br/>管理员的访问量为" + Application["admin"]);
}
else
{
Response.Write("管理员的访问量为:0");
}
if (Application["user"]!=null)
{
Response.Write("<br/>用户的访问量为" + Application["user"]);
}
else
{
Response.Write("用户的访问量为:0");
}
}
这是另外一个叫count.aspx页面的后台代码
为什么Button1_Click事件之后就报异常了呢?
求各位大神指导,在线等待中......
|