This is a common necessity that I have on every page:
if (session["LoggedIn"] == null || ((bool)session["LoggedIn"] != true))
....//user is not logged in. return.
I was wondering if there is a way to create a Helper class with the method signature bool IsLoggedIn()and call this method from the page so that it can automatically check whether the page from which it was called was session["LoggedIn"]set to true? Something like that:
class Helper
{
public bool IsLoggedIn()
{
System.Web.UI.Page page = ***FindCallerPageSomeHow***();
if(page.session["LoggedIn"] == null || ((bool)page.session["LoggedIn"] != true))
return false;
return ((bool)page.HpptContext.Session["LoggedIn"] == true);
}
}
Of course, I could try to implement an interface for each codebehind class, but this repeats. Also, I could go in HttpContextfor IsLoggedIn, but it's a bit of a nuisance ..
Any ideas? Is there an easy-to-implement template for this?
source
share