登录后可在网站上访问页面

时间:2013-04-29 12:29:57

标签: c# authentication login

我需要一个代码,我可以使用它来在网站上通过登录进行身份验证后访问网页,这意味着我希望在特定用户登录时可以访问它。 任何能帮助我的人。

(注意:我是一个更瘦的,还是新手)

提前致谢

2 个答案:

答案 0 :(得分:0)

表单身份验证怎么样? {{3P>

答案 1 :(得分:0)

然后我为你写的一个非常简单的程序

 readonly SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["VerbaLinksConString"].ToString());

 try
 {
    SqlCommand cmd  = new SqlCommand("Select txt_Password from table where txt_user_name = '"+txtUserName.Text+"' and txt_Pwd = '"+txtPassword.Text+"'",sqlCon);
   sqlCon.Open();
   SqlDataReader dr = cmd.ExecuteReader();
   If(dr.Read())
   {
     Response.Redirect("HomePage.aspx");
   }
   else
   {
     Response.Write("Either userId or Password is wrong");
   }
   SqlCon.Close(); 
}
Catch(SqlException ex)
 {

 }