I m newb in asp.net. I m working for an example with Membership class in ASP.NET. I have some pages in my project e.g. default.aspx, page1.aspx, page2.aspx. I have put login control in default.aspx. Now I want to check authentication of user when user want to access any page. Already I achieved this thing to put below snippest in Page_Load event in every Page. But want some suggestion so that i can remove this duplicate code from every page. and implemete some logic which can be applicable on every page. Do i need to use global.asax or any class which could be inherite in all page an check authentication?
if(!HttpContext.Current.User.Identity.IsAuthenticated)
{
Response.redirect("default.aspx");
}
You can set up your default login page from the authentication element of the web.config file in the root of your asp.net application.
an example…
Controlling access to files and folders is done via the authorisation element.
an example…
See the documentation for full details and more examples.