Click here to Skip to main content
15,886,100 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a small application in Asp.net . I have created an admin panel in that. Certain Pages are accessible to admin login only . I want to restrict access to those pages if admin loggin session variable is not set. On checking whether the SESSION variable is set , it still redirects me on the login page even if the session variable is set, please go through my code
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        if (Convert.ToString(Session["loggeduername"])=="")
        {
           Response.Redirect("adminlogin.aspx");
        }



    }
}
Posted
Updated 25-Jul-13 1:43am
v3
Comments
ridoy 25-Jul-13 14:03pm    
You posted 2 same question.Should delete one as you found a solution on other question.

1 solution

C#
protected void Page_Load(object sender, EventArgs e)
    {
            String message="this is a session debug :"+Session["loggeduername"];
            Response.Write("<script>alert('"+message+"')</script>");
            if (Session["loggeduername"]==null)
            {
               Response.Redirect("adminlogin.aspx");
            }

    }
 
Share this answer
 
v4
Comments
Thanks7872 25-Jul-13 7:49am    
This will redirect to adminlogin.aspx each time when the session contains value. The OP is intended just the reverse.
Chui PuiKwan 25-Jul-13 8:53am    
ths for your reminder,and i updated the code.
Thanks7872 25-Jul-13 10:50am    
It will still give an error. There should be String message="this is a session debug :"+Session["loggeduername"].ToString();
Chui PuiKwan 25-Jul-13 20:58pm    
can you debug it?
Response.Write(message);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900