0
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);
                }
             }
          }
       }
    }
}

Edited by __avd: Added [code] tags.

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by az23rilek
0

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....

0

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();
    //        }
    //}
    //}
    
}

Edited by __avd: Added [code] tags.

0
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();
    //        }
    //}
    //}

}

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.