On a .aspx page load, you may want to check if the session is valid. If valid continue with the page load and if not redirect to login.aspx page.
We write our own class which inherits from System.Web.UI.Page.
public class CustomClass : System.Web.UI.Page
{
public CustomClass()
{
}
protected override void OnInit(EventArgs e)
{
//Check if the page is no public and the user session is valid
if (isSessionValid())
{
// Continue work.
}
else
{
RedirectToLogin();
}
this.Load += new EventHandler(CustomClass_Load);
base.OnInit(e);
}
protected void CustomClass_Load(object sender, EventArgs e)
{
}
public void RedirectToLogin()
{
Response.Redirect(this.ResolveUrl("~/Login.aspx"));
}
}
Then we can inherit our .aspx.cs class from our custom class.public partial class Mywebsite_PaymentPage : CustomClass
{
}
This will result in checking the user session validity every time "PaymentPage.aspx" loads. You can inherit all the .aspx.cs page classes, which require session based authentication, from this CustomClass.cs. This will eliminate the trouble of checking the session in each and every page load method individually.
No comments:
Write comments