I have a page which allow user to login.
Once they are login, a cookie will create with a value and redirect the user to specify pages..
And a master page will be load. Inside the master page will retrieve the cookie value and display if the cookie value not null.
and also provided a get method which retrieve the cookie value.
But in every child pages i do have link to this master page Master.getCookieValue
Now my problem is that any way/trick is able to do one checking of cookie value in master page only instead of doing the checking in every single child page?
If my explanation not very clear..
Code Below
protected void SetDestinationURL(object sender, EventArgs e)
{
if (loginMember() || loginManager())
{
HttpCookie UsernameCookies = new HttpCookie("Username");
UsernameCookies.Value = txtUsername.Text;
UsernameCookies.Expires = DateTime.Now.AddHours(1);
Response.Cookies.Add(UsernameCookies);
BasePage.Alert.Show("Please proceed to Profile Modification to update your Monthly Budget & Saving Rate");
}
if (loginMember())
Response.Redirect("~/Member/Home.aspx");
else if (loginManager())
Response.Redirect("~/Manager/Home.aspx");
else
BasePage.Alert.Show("Unauthorized User Access");
}
In Member/Home.aspx
which loaded a master page Member.Master
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["Username"] != null)
{
hlUsername.Text = Request.Cookies["Username"].Value;
showProfilePicture();
}
else
Response.Redirect("~/ErrorPages/401.aspx");
}
public string getUsername
{
get { return Request.Cookies["Username"].Value; }
}
In every child pages which linked this master must to get the cookie value for some purpose.
Of course, if the cookie is expired, every child pages cannot be access, thus i do the cookie checking in every child pages.
protected void Page_Load(object sender, EventArgs e)
{
if(Request.Cookies["Username"] != null)
Response.Write(Master.getUsername);
else
Response.Redirect("ErrorPages.aspx");
}
So is that any way to do the cookies value checking instead of checking in all child pages?