sandeep kumar

sandeep kumar

  • NA
  • 58
  • 12.4k

Sessions: If user listed is not logged in, then redirect.

May 23 2018 12:28 PM
Hi Everyone,
 
I have problem, If the session user is not the desired user then redirect to homepage.
In my page load I have written below code but it is not working( No Errors, But unable to login other than the given user name in the page load).
  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3. if (Session["username"] == null)  
  4. {  
  5. Response.Redirect("Login.aspx");  
  6. }  
  7. Label1.Text = " " + Session["username"];  
  8. else if (Session["username"] != null) ;  
  9. {  
  10. Session["username"] = Label1.Text = "abc";  
  11. Session["username"] = Label1.Text = "xyz";  
  12. }  
  13. Response.Redirect("error.aspx")  
Here "abc" & "xyz" are the two users which I dont want to give access to page want to redirect to home page.
 
Please help me.
Thanks,
Sandeep

Answers (1)