2015-01-17 5 views
-4
public partial class Admin_Login : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 
     SqlConnection con = null; 
     ConectionStrings cs = new ConectionStrings(); 
     SqlCommand comm = null; 
    SqlDataReader reader = null; 
    SqlDataAdapter da; 
    protected void btnadmin_login_Click(object sender, EventArgs e) 
    { 


      con = new SqlConnection(cs.Db); 
      con.Open(); 
      //string logincheck = "select * from Admin_login where admin_name [email protected] and [email protected]"; 
      string login = " Select * from Admin_login where admin_name = '" + txtadmin_name.Text + "' and admin_pwd = '" + txtadmin_pwd.Text + "' "; 

      comm=new SqlCommand(login,con); 
    // comm.Parameters.AddWithValue("@username", txtadmin_name.Text); 
    //  // da = new SqlDataAdapter(login, con); 
    // comm.Parameters.AddWithValue("@admin_pwd", txtadmin_pwd.Text.Trim()); 
    // 
     reader = comm.ExecuteReader(); 
      if (reader.Read()) 
      { 


       Response.Redirect("Admin Add_Books.aspx"); 

      } 
      else 
      { 
       ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>"); 
      } 

      con.Close(); 









    } 
} 

Asp.net 로그인 및 세션

public partial class Admin_Login : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 
     SqlConnection con = null; 
     ConectionStrings cs = new ConectionStrings(); 
     SqlCommand comm = null; 
    SqlDataReader reader = null; 
    SqlDataAdapter da; 
    protected void btnadmin_login_Click(object sender, EventArgs e) 
    { 


      con = new SqlConnection(cs.Db); 
      con.Open(); 
      //string logincheck = "select * from Admin_login where admin_name [email protected] and [email protected]"; 
      string login = " Select * from Admin_login where admin_name = '" + txtadmin_name.Text + "' and admin_pwd = '" + txtadmin_pwd.Text + "' "; 

      comm=new SqlCommand(login,con); 
    // comm.Parameters.AddWithValue("@username", txtadmin_name.Text); 
    //  // da = new SqlDataAdapter(login, con); 
    // comm.Parameters.AddWithValue("@admin_pwd", txtadmin_pwd.Text.Trim()); 
    // 
     reader = comm.ExecuteReader(); 
      if (reader.Read()) 
      { 


       Response.Redirect("Admin Add_Books.aspx"); 

      } 
      else 
      { 
       ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>"); 
      } 

      con.Close(); 









    } 
} 

모든 것이 괜찮아하지만 로그 아웃 페이지

+0

더 명확히하십시오. 문제가 무엇입니까? 무엇을 시도 했습니까? – JoJo

+0

'url same copy my homepage same'을 설명 해주시겠습니까? (-1) - 명확하지 않다. –

답변

0

전에 다시 내 홈 페이지 같은과 URL이 동일한 사본이 내 관리자 인 경우 로그인 패널

public partial class Admin_Login : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 
    SqlConnection con = null; 
    ConectionStrings cs = new ConectionStrings(); 
    SqlCommand comm = null; 
    SqlDataReader reader = null; 
SqlDataAdapter da; 
    protected void btnadmin_login_Click(object sender, EventArgs e) 
    { 


     con = new SqlConnection(cs.Db); 
     con.Open(); 
     //string logincheck = "select * from Admin_login where admin_name [email protected] and [email protected]"; 
     string login = " Select * from Admin_login where admin_name = '" + txtadmin_name.Text + "' and admin_pwd = '" + txtadmin_pwd.Text + "' "; 

     comm=new SqlCommand(login,con); 
// comm.Parameters.AddWithValue("@username", txtadmin_name.Text); 
//  // da = new SqlDataAdapter(login, con); 
// comm.Parameters.AddWithValue("@admin_pwd", txtadmin_pwd.Text.Trim()); 
// 
    reader = comm.ExecuteReader(); 
     if (reader.Read()) 
     { 


      Response.Redirect("Admin Add_Books.aspx"); 

     } 
     else 
     { 
      ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>"); 
     } 

     con.Close(); 
    } 
} 

를 열면 내 다른 페이지와 때 내가 로그인 버튼을 클릭

내가 로그 아웃 마이 페이지 t 암탉의 다시 로그인 패널 ..... 모든게 괜찮습니다하지만 하나의 Probelm 내가 backpage를 클릭하면 로그인하지 않고 내 내부 페이지 또는 coppy URL을 내 내부 페이지 로그 아웃 후 다시 브라우저에서 내 URL을 넣어 이 페이지 로그인

없이 보여하지만 난 브라우저 여기

 public partial class Admin_Add_Books : System.Web.UI.Page 
     { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
     ConectionStrings cs = new ConectionStrings(); 
     SqlConnection con = new SqlConnection(cs.Db); 
     con.Open(); 

     SqlCommand cmd = new SqlCommand("Select * from Library order by mem_id", con); 
     DataTable tb = new DataTable(); 

     SqlDataAdapter da = new SqlDataAdapter(cmd); 

     da.Fill(tb); 
     tb.AcceptChanges(); 
     GridView_all_records.DataSource = tb; 
     GridView_all_records.DataBind(); 
     con.Close(); 
} 

protected void Button1_Click1(object sender, EventArgs e) 
{ 
    Response.Redirect("Admin Login.aspx"); 
} 
} 
0

이 페이지 코드 헤이 먼저 제대로 개념을 이해할 필요가

저장 암호가 없습니다.
하나는 SQLDataAdapter를 사용했으며 연결을 열고 닫았습니다. SQLDataAdapter는 닫힌 Connection에 사용되므로 필요하지 않습니다. Google에서 Asp.net의 열기 및 닫기 연결을 검색하고 Microsoft 공식 사이트에서 읽으십시오.

둘째로, 요점을 잘 이해하면 어디서나 세션을 사용했는지 알 수 없습니다. 로그인에 성공하면 Session에 일부 데이터를 저장해야하며 각 페이지로드시 해당 세션이 비어 있지 않은지 확인하십시오. 따라서 다시 로그인 페이지로 리디렉션하면 미개봉 사용자가 내 페이지를 볼 수 없습니다. 아래의 예를 확인하십시오.

protected void Page_Load(object sender, EventArgs e) 
    { 
    if (Session["AdminLoginDetails"] == null) 
    { 
     Response.Redirect("../Default.aspx"); 
    } 
    } 

각 페이지의로드 이벤트에 지금

if (reader.Read()) 
    { 
     Session["AdminLoginDetails"] = "logged In"; //Should actually be login details(datatable) 
     Response.Redirect("Admin Add_Books.aspx"); 
    } 

(즉 로그인없이 볼 수 없습니다한다)는 희망이 도움이.
또한 질문을 편집하고 대답을 질문으로 추가하지 마십시오. 수정 버튼을 사용하여 문제를 편집하고 질문을 이해할 수있게하십시오. 귀하의 질문은 간단했지만 질문하는 방식으로 어려움을 겪었습니다.