using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

    }
    protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
    {
        //if (HttpContext.Current.User.Identity.IsAuthenticated)
        //{
        //    Users user;

        //    if (Session["Users"] == null)
        //    {
        //        Session["Users"] = Users.(HttpContext.Current.User.Identity.Name);
        //    }

           //user = (Login1_Authenticate)Session["Users"];


        //   }
        //}

        if (string.Compare(Session["UserType"].ToString(), "Admin", true) == 0)>>>>This part shows e mistake
       {
            if (e.Item.Text == "Home" ||
                e.Item.Text == "Menu (Dietry)" ||
                e.Item.Text == "Exercise Plan" ||
                e.Item.Text == "Educational Content" ||
                e.Item.Text == "Videos" ||
                e.Item.Text == "Others")
            {
                this.Menu1.Items.Remove(e.Item);
            }
        }
        else
        {
            if (string.Compare(Session["UserType"].ToString(), "ContentUser", true) == 1)
            {
                if (e.Item.Text == "Upload Data File" ||
                e.Item.Text == "Menu (Dietry)" ||
                e.Item.Text == "Exercise Plan" ||
                e.Item.Text == "Educational Content" ||
                e.Item.Text == "Videos" ||
                e.Item.Text == "Others")
                {
                    this.Menu1.Items.Remove(e.Item);
                }
            }
         else
         {
            if (string.Compare(Session["UserType"].ToString(), "Clinicians", true) == 2)
             {
                if (e.Item.Text == "Menu (Dietry)" ||
                e.Item.Text == "Exercise Plan" ||
                e.Item.Text == "Educational Content" ||
                e.Item.Text == "Videos" ||
                e.Item.Text == "Others")
                {
                    this.Menu1.Items.Remove(e.Item);
                }
             }
          }
       }
    }
}

Recommended Answers

All 4 Replies

well,when a specific user successfully login,tehy will then be checked according to their "userType" found inside the database afterwhich they will be redirected to their respective pages,for example,admin users will go to admin page etc...each user's page has its own nav bar....

This is from the Login Page

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient; 
using System.Data.OleDb; 
using System.Data.SqlTypes;
using System.Collections.Generic;
using System.Linq;


public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Button btn = (Button)this.Login1.FindControl("btnReset");

            btn.Attributes.Add("onclick", "return ClearLogin()");
        }

        this.MessageBox1.SetIsButtonClicked += new IsButtonClicked(MessageBox1_SetIsButtonClicked);
    }
    void MessageBox1_SetIsButtonClicked(bool isClicked)
    {

    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        if (UserManager.ValidateUser(this.Login1.UserName, this.Login1.Password))
        {
            // TODO: Get the user type from the User table in the database
            Session["UserType"] = "Admin";
            //Session["UserType"] = "ContentUser";
            //Session["UserType"] = "User";
            //Session["UserType"] = "Clinicians";
            FormsAuthentication.RedirectFromLoginPage(this.Login1.UserName, true); 
        }
        else 
        {
            FormsAuthentication.RedirectFromLoginPage(this.Login1.UserName, true);
            this.MessageBox1.MessageText = "Invalid Login ID or Password";
            this.MessageBox1.MessageTextColor = System.Drawing.Color.Red;
            this.MessageBox1.ShowMessageBox = true;
        }
    }



    //protected void LoginButton_Click(object sender, EventArgs e)
    //{
    //    SqlConnection conn = new SqlConnection("Data Source=SN800002259-0;Initial Catalog=TeleCare;User ID=sa;Password=$qlit@g";
      
    //    string mySQL = "SELECT * FROM Users";

    //    conn.Open();

    //    SqlCommand cmd = new SqlCommand(mySQL, conn);

    //    SqlDataReader dr;

    //    dr = cmd.ExecuteReader();

    //    while (dr.Read())
    //    {
    //        string loginId = dr["LoginCode"].ToString(); //to verify the Name enter have a match in the user table
    //        string password = dr["Password"].ToString(); //to verify the Password enetr have a match in the user table
            
    //        if (UserName.Text != loginId)
    //        {
    //            lblStatus.Text = "Invalid login or unauthorised user";
    //        }

    //        else
    //        {
    //            if ((UserName.Text == loginId) && (Password.Text == password))
    //            {
    //                txtInvisible.Text = txtLogin.Text;
    //                //Session["UserID"] = txtInvisible.Text;
    //                Response.Redirect("Default.aspx");
    //            }

    //            dr.Close();
    //            conn.Close();
    //        }
    //}
    //}
    
}
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient; 
using System.Data.OleDb; 
using System.Data.SqlTypes;
using System.Collections.Generic;
using System.Linq;


public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Button btn = (Button)this.Login1.FindControl("btnReset");

            btn.Attributes.Add("onclick", "return ClearLogin()");
        }

        this.MessageBox1.SetIsButtonClicked += new IsButtonClicked(MessageBox1_SetIsButtonClicked);
    }
    void MessageBox1_SetIsButtonClicked(bool isClicked)
    {

    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        if (UserManager.ValidateUser(this.Login1.UserName, this.Login1.Password))
        {
            // TODO: Get the user type from the User table in the database
            Session["UserType"] = "Admin";
            //Session["UserType"] = "ContentUser";
            //Session["UserType"] = "User";
            //Session["UserType"] = "Clinicians";
            FormsAuthentication.RedirectFromLoginPage(this.Login1.UserName, true); 
        }
        else 
        {
            FormsAuthentication.RedirectFromLoginPage(this.Login1.UserName, true);
            this.MessageBox1.MessageText = "Invalid Login ID or Password";
            this.MessageBox1.MessageTextColor = System.Drawing.Color.Red;
            this.MessageBox1.ShowMessageBox = true;
        }
    }



    //protected void LoginButton_Click(object sender, EventArgs e)
    //{
    //    SqlConnection conn = new SqlConnection("Data Source=SN800002259-0;Initial Catalog=TeleCare;User ID=sa;Password=$qlit@g";

    //    string mySQL = "SELECT * FROM Users";

    //    conn.Open();

    //    SqlCommand cmd = new SqlCommand(mySQL, conn);

    //    SqlDataReader dr;

    //    dr = cmd.ExecuteReader();

    //    while (dr.Read())
    //    {
    //        string loginId = dr["LoginCode"].ToString(); //to verify the Name enter have a match in the user table
    //        string password = dr["Password"].ToString(); //to verify the Password enetr have a match in the user table

    //        if (UserName.Text != loginId)
    //        {
    //            lblStatus.Text = "Invalid login or unauthorised user";
    //        }

    //        else
    //        {
    //            if ((UserName.Text == loginId) && (Password.Text == password))
    //            {
    //                txtInvisible.Text = txtLogin.Text;
    //                //Session["UserID"] = txtInvisible.Text;
    //                Response.Redirect("Default.aspx");
    //            }

    //            dr.Close();
    //            conn.Close();
    //        }
    //}
    //}

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.