2016-05-16 53 views
1

我想這個 代碼重定向:Response.Redirect的不正常

protected void btnLogin_Click(object sender, EventArgs e) 
    { 
     User user = ConnectionClass.LoginUser(txtUsername.Text, txtPassword.Text); 

     if (user != null) 
     { 
      //Store login variables in session 
      Session["login"] = user.Username; 
      Session["user_type"] = user.Type; 

      var userType = (string)Session["user_type"]; 
      if (userType == "user" && userType == "special_user") 
      { 
       Response.Redirect("~/Pages/Customers/Quotation_Customers.aspx"); 
      } 

     } 
     else 
     { 
      lblError.Text = "Login Failed"; 
     } 

    } 

是想給我重定向到另一個網頁,但代碼不重定向 可言。

+1

是否存在特定錯誤或異常? – Baso

+5

將你的'&&'操作符切換到'||'。它目前總是返回false。 –

+0

不是這是一個邏輯錯誤。 –

回答

5
if (userType == "user" && userType == "special_user") 

這不可能是真實的。該字符串不能等於兩個不同的字符串。你的意思是OR(||)嗎?

+0

哈哈。我看到你對這個邏輯發表了一個評論,然後你一定是喜歡,「哦,這實際上是問題!」 –