Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Prevent to Access Adminpage

Amin BhrAmin Bhr iranMember Posts: 1

Hi All
im trying to use Sessions to Authentication of the Admins and Users
but it isnt work
here is my code
i have a database with memberid membername & memberpass & membertype
and i say if membertype=admin then redirect to adminpanel.aspx if membertype=user
then redirect to userpanel.aspx else go to 404.aspx
and i use dbml model datalinksql
protected void ButtonLogin_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 in my adminpanel page i trying to use this
if (Session["MemberType"] != null && Session["MemberType"].ToString() == "Admin") { Response.Redirect("~/Admin/AdminPanel.aspx"); } else if (Session["MemberType"] != null && Session["MemberType"].ToString() == "User") { Response.Redirect("~/User/UserPanel.aspx"); } else { Response.Redirect("~/404.aspx"); }
it will redirect me to adminpage when i logged in but show erorr : this page is not working :(
but without these codes everything is ok ! why? what can i do?

Sign In or Register to comment.