I’m trying to set a value to true after the user has been authenticated, so that they can use the page after authentication. When I set the value to true and redirect them to that same page that value is false again. I’m sure it has to do with different instances of the class but I dont know how to fix it.
This is the class that sets the value:
if (IsUserAuthorized())
{
Admin admin = new Admin
{
IsAuthorized = true
};
Response.Redirect("~/Admin.aspx");
}
else
{
LblErrorMessage.Text = "Please check your \"User Name\" or \"Password\" and try again.";
}
This is the class that needs to know the value:
public partial class Admin : System.Web.UI.Page
{
public bool IsAuthorized { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (IsAuthorized)
{//Do something} }
else
{
Response.Redirect("~/UserAuthentication.aspx");
}
}
classes do not persist between pages. What you need is either of the following two