2011-03-16 315 views
1

我正在使用表單身份驗證並已將憑據存儲在Web.config中,因爲只有兩個憑據。目前我有一個登錄頁面,認證將重定向到default.aspx頁面或返回url。我想根據憑證重定向到不同的頁面,即form1.aspx或form2.aspx。 當前使用login.aspx頁面應重定向到不同的頁面

if (FormsAuthentication.Authenticate(txtUser.Text, txtPassword.Text)) 
{ 
    FormsAuthentication.RedirectFromLoginPage(txtUser.Text, false); 
} 
+0

你在主題行中不需要「Asp.net c#」。這就是標籤的用途。 – 2011-03-16 04:51:44

回答

1

使用Response.Redirect。

if (FormsAuthentication.Authenticate(txtUser.Text, txtPassword.Text)){ 
Response.Redirect("URLofPageYouWantToRedirectTo"); 
} 
2

是這樣的?

if (FormsAuthentication.Authenticate(txtUser.Text, txtPassword.Text)) 
    { 
      switch (txtUser.Text) 
      { 
        case "alice": 
          Response.Redirect("form1.aspx"); 
          break; 
        case "bob": 
          Response.Redirect("form2.aspx"); 
          break; 
        default: 
          FormsAuthentication.RedirectFromLoginPage(txtUser.Text, false); 
          break; 
      } 
    } 
+0

+1您比我更仔細地閱讀了這個問題。 – 2011-03-16 04:56:44