Shared and object References

Discussion in 'ASP .Net' started by tshad, Jan 9, 2006.

  1. tshad

    tshad Guest

    I am trying to build a small shared routine that I call in all my pages. I
    don't want to create an object reference as I just want to make a routine
    that I can use to add in code that needs to be executed at the beginning of
    all my pages with having to go change all the pages whenever this is needed.

    Here is the routine I am setting up:
    ***********************************************************
    Imports System
    Imports System.Web
    Imports System.IO
    Imports System.Web.UI
    Imports System.Web.SessionState
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Web.HttpCookie
    Imports System.Web.HttpCookieCollection
    Imports System.Web.HttpResponse
    Imports System.Web.HttpRequest
    imports System.Web.HttpContext
    Imports System.Web.HttpApplication
    Imports System.Web.HttpApplicationState
    Imports System.Collections
    Imports FtsData

    NameSpace MyFunctions

    Public Class PageLoad

    Public Shared sub InitialPageLoad ()

    HttpContext.Current.Session("User").LastPageVisited =
    System.Web.HttpContext.Request.ServerVariables("PATH_INFO")

    end sub

    End Class
    End Namespace
    ****************************************************************************
    *******

    but I am getting an error on the System.Web.HttpContext.Request:

    C:\Inetpub\wwwroot\staffingworkshop\Classes\PageLoad.vb(26) : error BC30469:
    Reference to a non-shared member requires an object reference.

    I just want to get the server variable Path_Info to get the current page.

    How can I do this without setting up an object reference?

    Thanks,

    Tom
    tshad, Jan 9, 2006
    #1
    1. Advertising

  2. Try:

    Dim context As HttpContext = HttpContext.Current
    If Not context Is Nothing Then
    context .Session("User").LastPageVisited =
    context.Request.ServerVariables("PATH_INFO")
    End If

    There is no Shared Request property of HttpContext object...

    "tshad" wrote:

    > I am trying to build a small shared routine that I call in all my pages. I
    > don't want to create an object reference as I just want to make a routine
    > that I can use to add in code that needs to be executed at the beginning of
    > all my pages with having to go change all the pages whenever this is needed.
    >
    > Here is the routine I am setting up:
    > ***********************************************************
    > Imports System
    > Imports System.Web
    > Imports System.IO
    > Imports System.Web.UI
    > Imports System.Web.SessionState
    > Imports System.Data
    > Imports System.Data.SqlClient
    > Imports System.Web.HttpCookie
    > Imports System.Web.HttpCookieCollection
    > Imports System.Web.HttpResponse
    > Imports System.Web.HttpRequest
    > imports System.Web.HttpContext
    > Imports System.Web.HttpApplication
    > Imports System.Web.HttpApplicationState
    > Imports System.Collections
    > Imports FtsData
    >
    > NameSpace MyFunctions
    >
    > Public Class PageLoad
    >
    > Public Shared sub InitialPageLoad ()
    >
    > HttpContext.Current.Session("User").LastPageVisited =
    > System.Web.HttpContext.Request.ServerVariables("PATH_INFO")
    >
    > end sub
    >
    > End Class
    > End Namespace
    > ****************************************************************************
    > *******
    >
    > but I am getting an error on the System.Web.HttpContext.Request:
    >
    > C:\Inetpub\wwwroot\staffingworkshop\Classes\PageLoad.vb(26) : error BC30469:
    > Reference to a non-shared member requires an object reference.
    >
    > I just want to get the server variable Path_Info to get the current page.
    >
    > How can I do this without setting up an object reference?
    >
    > Thanks,
    >
    > Tom
    >
    >
    >
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=, Jan 9, 2006
    #2
    1. Advertising

  3. tshad

    tshad Guest

    "Sergey Poberezovskiy" <> wrote
    in message news:...
    > Try:
    >
    > Dim context As HttpContext = HttpContext.Current
    > If Not context Is Nothing Then
    > context .Session("User").LastPageVisited =
    > context.Request.ServerVariables("PATH_INFO")
    > End If
    >
    > There is no Shared Request property of HttpContext object...


    Oh.

    I thought it was compaining that my InitialPageLoad was shared and needed to
    be an object.

    But you're saying I just have to create an object context inside my shared
    routine.

    I'll try that.

    Thanks,

    Tom
    >
    > "tshad" wrote:
    >
    > > I am trying to build a small shared routine that I call in all my

    pages. I
    > > don't want to create an object reference as I just want to make a

    routine
    > > that I can use to add in code that needs to be executed at the beginning

    of
    > > all my pages with having to go change all the pages whenever this is

    needed.
    > >
    > > Here is the routine I am setting up:
    > > ***********************************************************
    > > Imports System
    > > Imports System.Web
    > > Imports System.IO
    > > Imports System.Web.UI
    > > Imports System.Web.SessionState
    > > Imports System.Data
    > > Imports System.Data.SqlClient
    > > Imports System.Web.HttpCookie
    > > Imports System.Web.HttpCookieCollection
    > > Imports System.Web.HttpResponse
    > > Imports System.Web.HttpRequest
    > > imports System.Web.HttpContext
    > > Imports System.Web.HttpApplication
    > > Imports System.Web.HttpApplicationState
    > > Imports System.Collections
    > > Imports FtsData
    > >
    > > NameSpace MyFunctions
    > >
    > > Public Class PageLoad
    > >
    > > Public Shared sub InitialPageLoad ()
    > >
    > > HttpContext.Current.Session("User").LastPageVisited =
    > > System.Web.HttpContext.Request.ServerVariables("PATH_INFO")
    > >
    > > end sub
    > >
    > > End Class
    > > End Namespace
    > >

    ****************************************************************************
    > > *******
    > >
    > > but I am getting an error on the System.Web.HttpContext.Request:
    > >
    > > C:\Inetpub\wwwroot\staffingworkshop\Classes\PageLoad.vb(26) : error

    BC30469:
    > > Reference to a non-shared member requires an object reference.
    > >
    > > I just want to get the server variable Path_Info to get the current

    page.
    > >
    > > How can I do this without setting up an object reference?
    > >
    > > Thanks,
    > >
    > > Tom
    > >
    > >
    > >
    tshad, Jan 9, 2006
    #3
    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. Nick Marden
    Replies:
    0
    Views:
    1,055
    Nick Marden
    Jan 17, 2004
  2. Roger Leigh
    Replies:
    8
    Views:
    412
    Karl Heinz Buchegger
    Nov 17, 2003
  3. Replies:
    3
    Views:
    430
    Victor Bazarov
    Nov 10, 2004
  4. Douglass Turner
    Replies:
    2
    Views:
    2,011
    Manfred Bartz
    Sep 4, 2003
  5. Jack Bates
    Replies:
    3
    Views:
    293
    Steven D'Aprano
    Aug 6, 2011
Loading...

Share This Page