Запретить гостям видеть администратора ASP.NET
hi all i want to prevent other people except user and admin see panel pages i tried to do this with session but i dont know why its not working i have a table in my database called members with MemberId,MemberUser,MemberPass,MemberType i want to check if membertype is "admin" redirect to adminpanel.aspx if its user redirect to userpanel.aspx else redirect to 404.aspx and i have a login page named login.aspx i used mdbl model linq to sql to do this this is the code of the login button protected void Button3_Click(object sender, EventArgs e) { EshopDataClassesDataContext db = new EshopDataClassesDataContext(); Member UserOne = db.Members.Where(t => t.MemberUser == txtUser0.Text && t.MemberPass == txtPass0.Text).FirstOrDefault(); if (UserOne != null) { Session["MemberId"] = UserOne.MemberId.ToString(); Session["MemberType"] = UserOne.MemberType; Session["MemberUser"] = UserOne.MemberUser; if (UserOne.MemberType == "Admin") { Response.Redirect("~/Admin/AdminPanel.aspx"); } else if (UserOne.MemberType == "User") { Response.Redirect("~/User/UserPanel.aspx"); } else { Label1.Visible = true; } } } and this is the code of page load of admin panel page but it has eror like this Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 10: protected void Page_Load(object sender, EventArgs e) Line 11: { Line 12: if (Session["MemberType"].ToString() == "Admin") Line 13: { Line 14: Response.Redirect("~/Admin/AdminPanel.aspx"); Source File: g:\ASP.net Capture\ASp\session 10\eshop\Admin\AdminPanel.aspx.cs Line: 12 what can i do ? and very sry for bad english :(
Что я уже пробовал:
protected void Page_Load(object sender, EventArgs e) { if (Session["MemberType"].ToString() == "Admin") { Response.Redirect("~/Admin/AdminPanel.aspx"); } else if (Session["MemberType"].ToString() == "User") { Response.Redirect("~/User/UserPanel.aspx"); } else { Response.Redirect("~/404.asp"); } }