You can create a BasePae class which inherits System.Web.UI.Page.
Override the OnInit method and write appropriate code in that which will
redirect to default page.
And inherit all your ASPX pages from BasePage class, instead of System.Web.UI.Page like this:-
And finally in your login page, simply set Session["UserName"] with user's name.
public class BasePage : System.Web.UI.Page { protected override void OnInit(EventArgs e) { if (Session["UserName"] == null) { Response.Redirect("~/LoginPage.aspx"); } } }
And inherit all your ASPX pages from BasePage class, instead of System.Web.UI.Page like this:-
public partial class HomePage : BasePage { protected void Page_Load(object sender, EventArgs e) { } }
And finally in your login page, simply set Session["UserName"] with user's name.
No comments:
Post a Comment