Skip to content
Loading
without login another pages should not be opened on browser
master cs page
  1. using System.Web.UI;  
  2. using System.Web.UI.WebControls;  
  3. using System.Data;  
  4. using System.Data.SqlClient;  
  5. using System.Configuration;  
  6. using System.Web.Security;  
  7. public partial class admin_MasterPage : System.Web.UI.MasterPage  
  8. {  
  9. protected void Page_Load(object sender, EventArgs e)  
  10. {  
  11. if (!this.Page.User.Identity.IsAuthenticated)  
  12. {  
  13. FormsAuthentication.RedirectToLoginPage();  
  14. }  
  15. Response.Cache.SetCacheability(HttpCacheability.NoCache);  
  16. Response.Cookies["Userid"].Expires = DateTime.Now.AddDays(-1);  
  17. Response.Cache.SetNoStore();  
  18. HttpCookie loginCookie = Request.Cookies["Login"];  
  19. if (loginCookie != null)  
  20. {  
  21. string name = loginCookie.Values["Name"];  
  22. string password = loginCookie.Values["Password"];  
  23. // User validation based on cookies if required for valid user as might be user can change his password in any cases  
  24. // so call your databse user login validation method  
  25. //if //(name.ToLower() == "sa" && password.ToLower() == "sa") // user validation code  
  26. Label1.Text = (string)Session["id"];  
  27. }  
  28. else  
  29. {  
  30. Response.Redirect("Admin_Loogin.aspx");  
  31. }  
  32. }  
  33. protected void Button1_Click(object sender, EventArgs e)  
  34. {  
  35. Response.Cookies["Userid"].Expires = DateTime.Now.AddDays(-1);  
  36. Response.Redirect("Admin_Loogin.aspx");  
  37. }  
  38. }  

2 Replies

Know the answer? Post it — somebody with the same question will find it here.