My application needs to show menus to five types of different users. For example, Administrator user can see all menus but Gestor user can see just one menu.
login's screen has the code below:
{
public partial class Login : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
}
protected void btnLogin_Click(object sender, EventArgs e)
DataSet ds = Login.ValidarLogin(txtUserID.Text, txtPassword.Text);
DataTable dt = ds.Tables[0];
if (dt.Rows.Count == 0)
{ messageBox.ShowMessage("Usuário ou Senha incorretos!!");
else
{ this.Session["UserID"] = dt.Rows[0]["Id"].ToString();
this.Session["UserName"] = dt.Rows[0]["Username"].ToString();
this.Session["Privileges"] = dt.Rows[0]["Permissao"].ToString();
Response.Redirect("Principal.aspx");
The class that controls and shows the menus is this:
else if (this.usuario.Permissao == Usuario.Permissoes.Concedente)
this.linkListConvenio.Visible = false;
this.linkListConcedente.Visible = false;
this.linkListPagamento.Visible = false;
this.linkListMeta.Visible = false; }
This class calls another method:
public static bool LoggedIn(HttpSessionState Session)
bool Result = true;
if (Session["UserName"] == null)
{ Result = false;
if (Session["UserID"] == null)
if (Session["Privileges"] == null)
return Result;
The problem happens in this lines:
if (this.usuario.Permissao == Usuario.Permissoes.Gestor)
and
Source error is : [NullReferenceException: Object reference not set to an instance of an object.]Is there a way where I can catch the attribute 'Permissao' combined to user from database and compare it in my logic condition to show the menus to the users?
Source error is : [NullReferenceException: Object reference not set to an instance of an object.]
Is there a way where I can catch the attribute 'Permissao' combined to user from database and compare it in my logic condition to show the menus to the users?