Is there a way I can avoid bringing in the Page object?

Discussion in 'ASP .Net' started by AAaron123, Feb 6, 2009.

  1. AAaron123

    AAaron123 Guest

    In App_Code I'd like to develop a library of common usage procedures. The
    following works but notice I had to bring in a Page object or both Session
    and Response would be undeclared.

    I believe this causes late binding. Correct?

    Is there a way I can avoid bringing in the Page object?

    Thanks



    Imports Microsoft.VisualBasic

    Public Class Utility

    Public Shared Sub SaveCookie(ByVal P As Page, ByVal CookieName As String,
    ByVal CookieValue As String)

    Dim styleCookie As HttpCookie = New HttpCookie(CookieName)

    styleCookie.Value = CookieValue

    styleCookie.Expires = DateTime.Now.AddYears(1)

    P.Response.Cookies.Add(styleCookie)

    P.Session(CookieName) = styleCookie.Value

    End Sub

    End Class
     
    AAaron123, Feb 6, 2009
    #1
    1. Advertising

  2. AAaron123

    AAaron123 Guest

    THAT FIXED IT.

    Not sure about what I read. The browser makes a request and HttpContext
    includes all the data in the request. Is that correct?

    One time in the debugger I tried to see what was in the 2 Items but it
    showed Nothing" for both. Are the Items of interest?

    Also, if HttpContext is the data in the browser request what is in the
    Response property?

    The doc's typically give a one-line description of the properties which is
    not enough for me.


    Thanks for the help


    "Patrice" <http://www.chez.com/scribe/> wrote in message
    news:...
    > See System.Web.HttpContext.Current to gain access to the current http
    > request.. The page object expose this as a convenience...
    >
    >
    > --
    > Patrice
    >
    > "AAaron123" <> a écrit dans le message de groupe
    > de discussion : uh3LAZ$...
    >> In App_Code I'd like to develop a library of common usage procedures. The
    >> following works but notice I had to bring in a Page object or both
    >> Session and Response would be undeclared.
    >>
    >> I believe this causes late binding. Correct?
    >>
    >> Is there a way I can avoid bringing in the Page object?
    >>
    >> Thanks
    >>
    >>
    >>
    >> Imports Microsoft.VisualBasic
    >>
    >> Public Class Utility
    >>
    >> Public Shared Sub SaveCookie(ByVal P As Page, ByVal CookieName As String,
    >> ByVal CookieValue As String)
    >>
    >> Dim styleCookie As HttpCookie = New HttpCookie(CookieName)
    >>
    >> styleCookie.Value = CookieValue
    >>
    >> styleCookie.Expires = DateTime.Now.AddYears(1)
    >>
    >> P.Response.Cookies.Add(styleCookie)
    >>
    >> P.Session(CookieName) = styleCookie.Value
    >>
    >> End Sub
    >>
    >> End Class
    >>
    >>

    >
     
    AAaron123, Feb 6, 2009
    #2
    1. Advertising

  3. AAaron123

    AAaron123 Guest


    >
    >> Also, if HttpContext is the data in the browser request what is in the
    >> Response property?

    >
    > The collection of objects used to create the final markup which will be
    > streamed to the client browser.
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net

    I can't figure how much it contains at a given time. If I'm in a code behind
    event that later will set some markup into a Literal control it obvisoly
    can't contain that markup yet. If I already wrote to it I guess it'll
    contain that. But what else. The contents of the .aspx file is subject to
    change by the code behind - so I'm confused about what Response does
    contain.

    There is lots of good tutorial stuff on the Internet butb sometimes the big
    picture is hard to discern.

    Thanks a lot
     
    AAaron123, Feb 6, 2009
    #3
  4. AAaron123

    AAaron123 Guest

    I got the following reply from George via e-mail instead of the NG because
    he clicked the wrong button. I implemented his "c" suggestion. Works well so
    I and thought I'd pass it on.

    a. It does not cause late binding.

    b. You can avoid using page but then you need to pass Response and Session
    to SaveCookie.

    c. The best way is to base you Utility from Page class and then your pages
    from
    Utility (instead of Page).

    On this case all you pages will have SaveCookie method from parent class and
    you do not need to pass Page object since it will have access to Response
    and Session since it's based of Page class.


    George.

    "AAaron123" <> wrote in message
    news:uh3LAZ$...
    > In App_Code I'd like to develop a library of common usage procedures. The
    > following works but notice I had to bring in a Page object or both Session
    > and Response would be undeclared.
    >
    > I believe this causes late binding. Correct?
    >
    > Is there a way I can avoid bringing in the Page object?
    >
    > Thanks
    >
    >
    >
    > Imports Microsoft.VisualBasic
    >
    > Public Class Utility
    >
    > Public Shared Sub SaveCookie(ByVal P As Page, ByVal CookieName As String,
    > ByVal CookieValue As String)
    >
    > Dim styleCookie As HttpCookie = New HttpCookie(CookieName)
    >
    > styleCookie.Value = CookieValue
    >
    > styleCookie.Expires = DateTime.Now.AddYears(1)
    >
    > P.Response.Cookies.Add(styleCookie)
    >
    > P.Session(CookieName) = styleCookie.Value
    >
    > End Sub
    >
    > End Class
    >
    >
     
    AAaron123, Feb 6, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yttrium
    Replies:
    7
    Views:
    2,541
    Yttrium
    Oct 15, 2003
  2. Alexander Malkis
    Replies:
    8
    Views:
    526
    Alexander Malkis
    Apr 14, 2004
  3. Roger23
    Replies:
    2
    Views:
    1,007
    Roger23
    Oct 12, 2006
  4. reju
    Replies:
    7
    Views:
    772
    Juan T. Llibre
    Mar 6, 2007
  5. Helge Elvik
    Replies:
    4
    Views:
    112
Loading...

Share This Page