I have my site set up to use Forms Authentication. For the pages that require a user to be logged in, I have some code that will redirect them to the login page if they aren't authenticated. This works fine if I put the code directly into the code-behind of each restricted page. But I want to be able to put that code into a master page, such that if I need to create a new restricted page I just use that master page. Here is the gist of the code-behind I'm trying to use:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MasterPages_Restricted : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated == false)
{
//code to redirect to the login page
}
else
...
Go to the complete details ...