2013-07-28 24 views
0

我試圖讓lo-gin屏幕將不同的用戶重定向到不同的屏幕。 我有一個數據庫表。 字段是。 SQL表設計如何使登錄屏幕將不同的用戶重定向到不同的屏幕?

username Varchar(50) 
password Varchar(50) 
Designation Text 
IsAdmin bit 

現在我有兩個分別文本域登錄按鈕

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.Configuration; 
using System.Data.SqlClient; 

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

    } 
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) 
    { 
     string username = Login1.UserName; 
     string password = Login1.Password; 
     string CurrentName; 

     string s; 
     s = WebConfigurationManager.ConnectionStrings["ovmsConnectionString"].ConnectionString; 
     SqlConnection con = new SqlConnection(s); 
     con.Open(); 
     string sqlUserName; 

     //FOR NORMAL USERS 

    if(username != null) 
      { 


      sqlUserName = "SELECT username,password FROM tblLogin WHERE username ='" + username + "' AND password ='" + password + "'"; 
      SqlCommand cmd = new SqlCommand(sqlUserName, con); 


      CurrentName = (string)cmd.ExecuteScalar(); 

      if (CurrentName != null) 
      { 
       Session["UserAuthentication"] = username; 
       Session.Timeout = 1; 
       Response.Redirect("start.aspx"); 
      } 
      else 
      { 
       Session["UserAuthentication"] = ""; 
      } 
     } 
    } 
} 

我想在登錄和管理不同的頁面(管理面板)後,顯示驅動程序不同的頁面。

我有兩個查詢,我只想通過一個FORM使管理員pannel登錄,用戶登錄屏幕和驅動程序登錄屏幕。

like : 
Query for driver 

SELECT  username, password, Designation 
FROM   dbo.tblLogin 
WHERE  (Designation LIKE 'driver') 

and for Admin Login 

SELECT  username, password, IsAdmin 
FROM   dbo.tblLogin 
WHERE  (IsAdmin = 1) 
+0

fyi:您可能想要按照您自己的條件見到[Bobby](http://bobby-tables.com/)。 Cleartext密碼在數據庫中?嘆。 – HABO

回答

0

您可以爲管理員創建兩個角色,爲司機創建兩個角色。

在您的登錄代碼中,檢查用戶所屬的角色並根據該角色進行重定向。

if(Roles.IsUserInRole(userName,「Admin」)) { return ReirectToAction(「」,「AdminHomepage」); } else { return ReirectToAction(「」,「DriversHomepage」); }

+0

其他用戶呢? – user2627493

+0

似乎我必須爲每個用戶做出一個角色,是你在說什麼。像我有會計師,老師,管理員.......等 – user2627493

+0

創建不同類型的用戶,你可以在應用程序的角色。舉個例子,司機和管理員是兩個不同的角色。如果我有30個驅動程序,我會將它們全部添加到角色驅動程序中。 –