Handling Context in ASP.net page

5 posts, 1 answers
  1. rtelles
    rtelles avatar
    11 posts
    Member since:
    Oct 2012

    Posted 14 Nov 2011 Link to this post

    I was reading thru the OpenAccess documentation and found 2 ways of dealing with the context in ASP.Net.

    1) Using Master Pages (easier to implement)
    2) Using HttpModule (by far more complicated and I could not even get it working as per Telerik examples online)


    Master Pages way is super easy to implement however what happens if I do not use Master pages? So I tried on a regular .aspx page to override both the OnInit  and Dispose methods and created a private variable to hold the context (pretty much the exact same way as what goes in the code of the Master Page approach).

    As follows:

            private WebContext context;

            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
                this.context = new WebContext();
            }

            public override void Dispose()
            {
                base.Dispose();
                this.context.Dispose();
            }


    So this works just as good as using the Master Page approach. However since Telerik does not mentions this approach I was wondering maybe something really wrong is going to happen down the line. Or maybe I am being too paranoid. Anyone could let me know if this 3rd approach is a big NO-NO? Or if is just as ok as the Master Page approach? If so then why would someone in their right mind even consider the HttpModule approach (I could not even get it working on my end).
  2. Answer
    Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 15 Nov 2011 Link to this post

    Hi Rtelles,

    You could use this approach for a single page as well not only with Master page.
    Another approach which you could use for handling the context can be found in this KB article.
    Hope that helps.

    Greetings,
    Damyan Bogoev
    the Telerik team

    NEW and UPDATED OpenAccess ORM Resources. Check them out!

  3. DevCraft banner
  4. rtelles
    rtelles avatar
    11 posts
    Member since:
    Oct 2012

    Posted 15 Nov 2011 Link to this post

    Thanks for the reply Damyan. Now I feel more at ease just using the context that way. I like a lot the way is shown in that article and will use it for the situations were I have multiple user controls on a page. It looks like a very straight forward way. Seems to me with these two options there is no need for the HttpModule approach.
  5. rtelles
    rtelles avatar
    11 posts
    Member since:
    Oct 2012

    Posted 15 Nov 2011 Link to this post

    (Double Post) It seems the Telerik forums are experiencing issues lately. I am getting a lot of error pages.
  6. Ivailo
    Admin
    Ivailo avatar
    318 posts

    Posted 18 Nov 2011 Link to this post

    Hello Rafael,

    Thanks for notifying us about your issues with the forum - we will check for possible problems. Do not hesitate to inform us if it appears again.


    Regards,

    Ivailo
    the Telerik team

    NEW and UPDATED OpenAccess ORM Resources. Check them out!

Back to Top
DevCraft banner