2014-09-09 4 views
0

고객이 사용자 이름과 암호를 입력하면 최종 사용자 또는 회계사로 로그인하기 위해 라디오 버튼을 선택해야합니다. 하지만 최종 사용자 라디오 버튼을 클릭하면 메인 페이지로 다시 리디렉션되지만 company.aspx 페이지에는 다시 리디렉션되지 않습니다. 친절 도움말 -Asp.net : 로그인 리디렉션 실패

내 코드 : company.aspx 뒤에

protected void Button1_Click(object sender, EventArgs e) 
{ 
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); 
    conn.Open(); 
    string checkuser = "select count(*) from Registration where USERNAME='" + TextBoxUsername.Text + "'"; 
    SqlCommand com = new SqlCommand(checkuser, conn); 
    int temp = Convert.ToInt32(com.ExecuteScalar().ToString()); 
    conn.Close(); 
    if (temp == 1) 
    { 
     conn.Open(); 
     string checkPasswordQuery = "Select password from Registration where USERNAME='" + TextBoxUsername.Text + "'"; 
     SqlCommand passComm = new SqlCommand(checkPasswordQuery, conn); 
     string password = passComm.ExecuteScalar().ToString().Replace(" ", ""); 
     if (password == TextBoxPassword.Text) 
     { 
      Session["New"] = TextBoxUsername.Text; 
      Response.Write("Password is correct"); 

      if (EndUserRadioButton.Checked) 
      { 
       Response.Redirect("Company.aspx"); 
      } 
      else if (AccountantRadioButton.Checked) 
      { 
       Response.Redirect("AccountantUploads.aspx"); 
      } 
     } 
     else 
     { 
      Response.Write("Password is not correct"); 
     } 
    } 
    else 
    { 
     Response.Write("Username is not correct"); 
    } 
} 

protected void RadioButton1_CheckedChanged(object sender, EventArgs e) 
{ 
    if (EndUserRadioButton.Checked) 
    { 
     Response.Redirect("Company.aspx"); 
    } 
    else if (AccountantRadioButton.Checked) 
    { 
     Response.Redirect("AccountantUploads.aspx"); 
    } 
} 
+0

SQL 주입을 방지 페이지가 다시 홈 페이지로 리디렉션됩니다. – user3806621

+0

죄송합니다. 어떻게해야합니까? –

+0

Company.aspx 페이지 (Page_Load 이벤트)의 코드를 게시 할 수 있습니까? – user3806621

답변

0

코드 :

공공 부분 클래스 회사 : System.Web.UI.Page { 문자열 _ConnectionString = ConfigurationManager.ConnectionStrings [ " ConnectionString "]. 연결 문자열; SqlConnection conn = 새 SqlConnection (ConfigurationManager.ConnectionStrings [ "ConnectionString"]. 연결 문자열);

protected void Page_Load(object sender, EventArgs e) 
    { 


     if (Session["New"] != null) 
     { 
      Label_welcome.Text += Session["New"].ToString(); 
     } 
     else 
      Response.Redirect("MainPage.aspx"); 


    } 



    protected void Button2_Click(object sender, EventArgs e) 
    { 
     Response.Redirect("ChangePassword.aspx"); 
    } 



    protected void Button1_Click(object sender, EventArgs e) 
    { 
     string _ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; 
     SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); 
     DataTable dt = new DataTable(); 
     string qry1 = "SELECT [USERNAME], [EMAIL], [PASSWORD], [STATE], [NAME], [CNAME], [ADDRESS], [TELEPHONE], [FAX], [TYPE], [AGENT] FROM [Registration] WHERE ([USERNAME] LIKE '%' + @USERNAME + '%')"; 
     SqlDataAdapter da = new SqlDataAdapter(qry1, conn); 
     SqlCommand com = new SqlCommand(qry1, conn); 
     da.SelectCommand.Parameters.AddWithValue("@USERNAME", TextBoxSearch.Text); 
     da.Fill(dt); 
     GridView1.DataSourceID = string.Empty; 
     GridView1.DataSource = dt; 

    } 

    protected void GridView1_OnRowSelected(object sender, GridViewSelectEventArgs e) 
    { 
     var username = Convert.ToString(GridView1.DataKeys[e.NewSelectedIndex].Value); 
     Response.Redirect("ViewUploads.aspx?USERNAME=" +username); 

    } 
+0

소스 코드를 디버그하고 Session [ "New"]이 null 인 이유를 분석하려고 시도 했습니까? – user3806621

0

양식 인증을 사용할 때 수동으로 사용자를 로그인하려면. FormsAuthentication.SetAuthCookie()를 사용하십시오.

예 :

username=txtUserName.text; 
FormsAuthentication.SetAuthCookie(username, false); 
Response.Redirect(url); 

Response.Redirect를 그냥 HTTP 클라이언트로 리디렉션 보냅니다.

매개 변수화 된 쿼리도 사용하십시오.

string checkPasswordQuery = "Select password from Registration where [email protected]"; 
SqlCommand passComm = new SqlCommand(checkPasswordQuery, conn); 
passComm.Parameters.AddWithValue("@userName",txtUserName.Text); 

이 당신은 성공적으로 로그인 한 후 로그인 세션 검사가 아마도 해당 세션은 null 또는 비어가 있는지 확인 Company.aspx/AccountantUploads.aspx 페이지에 뒤에 코드를 확인해야

관련 문제