2012-02-10 89 views
1

什麼,我試着做的是如何爲不同用戶提供具有相同登錄頁面的不同用戶頁面?

我有共同的登錄頁面有4個用戶每個人都有不同的角色 和我有一個辛格運河主網頁,我有不同的contorls .....如何提供身份驗證自己與分配給them..regarding上thier角色,他們應該被引導到指定網頁的頁面contorls ....

 user 1 manager he needs only some controls on the page so when he logins the master page should contain only the controls assgned to him 

applys同樣爲所有用戶

任何一個可以幫我... ...刨,我不知道從哪裏開始....

+0

... – Madhu 2012-02-10 08:36:40

回答

2

試一試的按鈕根據您的要求,你需要動態地添加母版頁上的控件...建立根據登錄四種不同的控件和加載基於登錄角色掌握頁點擊

   SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DebitCareBankApp;Data Source=SSDEV7-HP\\SQLEXPRESS"); 
     string cmdStr = "select LoginType from Login where UserName='" + TxtUserName.Text + "' AND Password = '" + TxtPassword.Text + "'"; 


     SqlCommand cmd = new SqlCommand(cmdStr, con); 
     con.Open(); 
     Object TypeUser = cmd.ExecuteScalar(); 
     con.Close(); 

     if (TypeUser != null) 
     { 
      LblError.Visible = false; 
      LblError.Text = ""; 
      if (TypeUser.ToString() == "Manager") 
      { 

       Response.Redirect("~//Administration/Manager/WorkManagement.aspx"); 
      } 
      else if (TypeUser.ToString() == "HR") 
      { 
       Response.Redirect("~//Administration/Hr/CalculateAndGeneratePayslips.aspx"); 
      } 
      else if (TypeUser.ToString() == "Employee") 
      { 
       Response.Redirect("~//Administration/CallingAgent/TodaysWork.aspx"); 
      } 
     } 
     else 
     { 
      LblError.Visible = true; 
      LblError.Text = "Invalid Credentials Entered, Try again";     
     } 
0

有這個方法簡單的方法是如下的步驟,你可以按照

  1. 保持一個默認的母版頁//(「MasterPage.master」)
  2. 根據需要添加儘可能多的母版頁// 「manager.master/Admin.master」
  3. 添加到頁面的默認母版頁
  4. 添加類文件中的app_code其中u可以映射動態母版

在App_Code文件

public class DynamicPage : System.Web.UI.Page 
    { 
     protected override void OnPreInit(EventArgs e) 
     { 
      string masterfile = getMasterPageFromDatabase(); 
      if (!masterfile.Equals(string.Empty)) 
      { 
       base.MasterPageFile = masterfile; 
      } 
      base.OnPreInit(e); 
     } 

     private string getMasterPageFromDatabase() 
     { 
      // check the conditions "manager.master/Admin.master" 
      return "Admin.master"; 
     } 
    } 

來.CS爲default.aspx.cs文件時添加這個類這將是 「System.Web.UI.Page」 與DynamicPage替換

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

    } 
} 

終於談到像

public partial class _Default : **DynamicPage** 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 
    } 

其餘部分將發生自動映射

希望這有助於!