我从别的地方抄来一段。NET的 登陆代码!
一直搞不清楚 Session覆值在着段代码什么地方写,如何写? 请各位高手指点, 谢谢!                           string userName=Request.Form["userName"].ToString();
string userPwd=Request.Form.Get("userPwd").ToString();

SqlConnection con=new SqlConnection("server=.;database=login;uid=sa;pwd=;");
con.Open();
SqlCommand cmd=new SqlCommand("select count(*) from login where userName='"+userName+"' and userPwd='"+userPwd+"'",con);
int count=Convert.ToInt32(cmd.ExecuteScalar());
if(count>0)
{
Response.Redirect("index_admin.aspx");
}
else
{
Response.Redirect("sb.htm");
}

解决方案 »

  1.   

    string userName=Request.Form["userName"].ToString();
    string userPwd=Request.Form.Get("userPwd").ToString();

    SqlConnection con=new SqlConnection("server=.;database=login;uid=sa;pwd=;");
    con.Open();
    SqlCommand cmd=new SqlCommand("select count(*) from login where userName='"+userName+"' and userPwd='"+userPwd+"'",con);
    int count=Convert.ToInt32(cmd.ExecuteScalar());
    if(count>0)
    {
                                     ///在这里写,用户已经可以登录了,就要记录session了,然后再跳转页面
                                         Session["User_ID"] = "XXX";
    Response.Redirect("index_admin.aspx");
    }
    else
    {
    Response.Redirect("sb.htm");
    }
      

  2.   

    copico(名字再长也不会引起各位坛友的高度重视和深刻考虑)
    这位大哥说的对
      

  3.   

    if(count>0)
    {
    Response.Redirect("index_admin.aspx");
    }