In this article i will show how you can create a secure page, which is only is the login session is active.
So for this first we will create a new asp.net application and two aspx pages and in first page add a new textbox and two button for performing the demo. First button will used for invoking hte session value and second will be used for checking weather the session value is null or not if null then redirect to second page. In second page we will redirect if the session value is null.
So on the button click add the below code. in this code i am assigning value to session .
Now on second button add the below code.
In above code i have checked if session value is null then redirect to the second page . In case of login page you can check the session value on page load.
So for this first we will create a new asp.net application and two aspx pages and in first page add a new textbox and two button for performing the demo. First button will used for invoking hte session value and second will be used for checking weather the session value is null or not if null then redirect to second page. In second page we will redirect if the session value is null.
So on the button click add the below code. in this code i am assigning value to session .
protected void btnGenerate_Click(object sender, EventArgs e)
{Session["SessionID"]=txtSession.Text;
}
{Session["SessionID"]=txtSession.Text;
}
Now on second button add the below code.
protected void btnCheck_Click(object sender, EventArgs e)
{if (Session["SessionID"] != null)
{txtSession.Text = Session["SessionID"].ToString();
}else
{Response.Redirect("Default2.aspx");
}
}
{if (Session["SessionID"] != null)
{txtSession.Text = Session["SessionID"].ToString();
}else
{Response.Redirect("Default2.aspx");
}
}
In above code i have checked if session value is null then redirect to the second page . In case of login page you can check the session value on page load.
Tags: Asp.Net , C#.Net
No comments:
Post a Comment