Using Application() variables in non-web classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Bischof

    Using Application() variables in non-web classes

    Hi All,

    I saved a variable to the Application() collection and I can access this
    from the aspx.vb code. However, I want to be able to access this variable
    from a simple class. I've seen where I can have the class inherit from one
    of the web classes, but I don't want to do that just for a simple class that
    needs one variable. Currently, I'm making a public property in the class and
    setting it during the Application_Sta rt() event. But I don't think this is
    the best approach. Is it possible to use the Application() collection from a
    simple class?

    Thanks,

    Brian


  • William F. Robertson, Jr.

    #2
    Re: Using Application() variables in non-web classes

    You should look into:

    System.Web.Http Context.Current .Application

    That will give you the application object of the current web request when
    the code runs.

    HTH,

    bill

    "Brian Bischof" <brian@nospam.b ischofsystems.c om> wrote in message
    news:ukudZXZQDH A.2320@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Hi All,
    >
    > I saved a variable to the Application() collection and I can access this
    > from the aspx.vb code. However, I want to be able to access this variable
    > from a simple class. I've seen where I can have the class inherit from one
    > of the web classes, but I don't want to do that just for a simple class[/color]
    that[color=blue]
    > needs one variable. Currently, I'm making a public property in the class[/color]
    and[color=blue]
    > setting it during the Application_Sta rt() event. But I don't think this is
    > the best approach. Is it possible to use the Application() collection from[/color]
    a[color=blue]
    > simple class?
    >
    > Thanks,
    >
    > Brian
    >
    >[/color]


    Comment

    • David Waz...

      #3
      Using Application() variables in non-web classes

      Absolutely...

      Add an import entry to the class:
      System.Web.Http Context
      Either at the top of your class, or under project
      properties.

      Then, in your class, you reference the
      Session/Application/Server etc objects via:

      {System.Web.Htt pContext.}Curre nt.
      {Application|Se ssion|Server etc}

      [color=blue]
      >-----Original Message-----
      >Hi All,
      >
      >I saved a variable to the Application() collection and I[/color]
      can access this[color=blue]
      >from the aspx.vb code. However, I want to be able to[/color]
      access this variable[color=blue]
      >from a simple class. I've seen where I can have the class[/color]
      inherit from one[color=blue]
      >of the web classes, but I don't want to do that just for[/color]
      a simple class that

      Comment

      • Brian Bischof

        #4
        Re: Using Application() variables in non-web classes

        Thanks for the quick response. It works great!

        Brian

        "William F. Robertson, Jr." <wfrobertson@kp mg.com> wrote in message
        news:ObIeBbZQDH A.1712@TK2MSFTN GP12.phx.gbl...[color=blue]
        > You should look into:
        >
        > System.Web.Http Context.Current .Application
        >
        > That will give you the application object of the current web request when
        > the code runs.
        >
        > HTH,
        >
        > bill
        >
        > "Brian Bischof" <brian@nospam.b ischofsystems.c om> wrote in message
        > news:ukudZXZQDH A.2320@TK2MSFTN GP12.phx.gbl...[color=green]
        > > Hi All,
        > >
        > > I saved a variable to the Application() collection and I can access this
        > > from the aspx.vb code. However, I want to be able to access this[/color][/color]
        variable[color=blue][color=green]
        > > from a simple class. I've seen where I can have the class inherit from[/color][/color]
        one[color=blue][color=green]
        > > of the web classes, but I don't want to do that just for a simple class[/color]
        > that[color=green]
        > > needs one variable. Currently, I'm making a public property in the class[/color]
        > and[color=green]
        > > setting it during the Application_Sta rt() event. But I don't think this[/color][/color]
        is[color=blue][color=green]
        > > the best approach. Is it possible to use the Application() collection[/color][/color]
        from[color=blue]
        > a[color=green]
        > > simple class?
        > >
        > > Thanks,
        > >
        > > Brian
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...