Results 1 to 2 of 2

Thread: where to put session checks when using master files - ASP.NET

  1. #1
    Join Date
    Jul 2004
    Rep Power

    Default where to put session checks when using master files - ASP.NET

    Ok, here I've a question to ask my fellow techjamaicans. With .Net all grown up, we find it boasting about a lot of features of which Master Files is one.
    Now I must say design with master files can make development cool, but to be honest I was a bit apprehensive when I first read about it way back when.

    Any way I have a situation to which I need alternate solutions...Since most of my site pages use a master page I decided to put the session checks there rather than having to include these checks on all the pages. From the jump this sounds like a good idea, however I found myself in a bind. Due to the fact that the page_load event of the content page is fired before that of the master page...some of my code is started to break.

    Case in point. Say a user logs on to my system...some session variables are created.
    Now, most pages use one of a number of session variables in their respective load event, for instance to...pull some user specific stuff from the db...Now if it so happens that the session times out...the content page load event will still try to do what its supposed to do...but oops no session variable...the situation only gets handled after, within the master page's load event...bummmer. I know it could solved by making redundant checks in each content page...but that would in essence be sucky...what ideas do you guys have.

  2. #2
    Join Date
    Dec 2002
    Rep Power


    In the Page_Init (Init event). This is triggered before Load. The Init for the Content page will also fire before the Init of the Master page, so you can override some stuff from here. BEWARE ViewState is not loaded at this point.

    I think what you really need to do is implement some helper functionality outside of your pages (content or master), that can be called from anywhere.

    This can be in the form of static methods (so u dont have the hassle to instantiate) or as a Singleton. This way my client code does not care if the 'Settings' were in the session or elsewhere, as all the implementation is hidden behind public methods and properties.

    Secondly, if this is to facilitate permissions/access control then i would suggest using Forms Authentication, setup roles and use Login Controls to control what content is visible to a particular type of user.

    I can give examples if any of this is relevant.
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts