Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Application object in dll library?

Application object in dll library?

Scheduled Pinned Locked Moved ASP.NET
asp-netquestioncsharphostingtutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CillyMe
    wrote on last edited by
    #1

    I'm building this class library which will be referenced from my ASP.NET code. The class library code need to access information stored in application variables. Any suggestion? QUESTION 1: My take at it: string sConn = oHttpContext.Current.Application["sConn"]; But I'm not quite sure how to retrieve reference to the HttpContext from code in class library... Constructor for HttpContext requires a HttpWorkerRequest, which is of type System.Web.Hosting.SimpleWorkerRequest. First, I don't know how to get at it. QUESTION 2: Can I do this instead: string sConn = ((HttpContext) this.context).Application["sConn"]; myaspxpage.aspx namespace .. { Page_Load(..) { someName.MyComponent oManager = new someName.MyComponent(this.Request); //QUESTION: Is it necessary for me to pass WorkerRequest object as argument to constructor? Also, is "this.Request" of type "WorkerRequest"? I prefer not to supply Request/Reponse object to component constructor - first it's cleaner, secondly, the component will run in process of the ASPNET application, we can "probably" retrieve the objects from library code, right? //This is yet another alternative, equally clumsy: someName.MyComponent oManager(this.Request, this.Response); } } Signature of HttpContext is: public HttpContext(HttpRequest, HttpResponse); public HttpContext(HttpWorkerRequest); HttpWorkerRequest is of type: System.Web.Hosting.SimpleWorkerRequest HttpResponse is of type: System.Web.HttpResponse HttpRequest is of type: System.Web.HttpRequest Also, why "Response" or "Request" object, shouldn't a HttpContext be associated with a "HttpApplication" object instead? For instance, I don't see Application object is related to Response or Request object in any way. Thanks!

    H 1 Reply Last reply
    0
    • C CillyMe

      I'm building this class library which will be referenced from my ASP.NET code. The class library code need to access information stored in application variables. Any suggestion? QUESTION 1: My take at it: string sConn = oHttpContext.Current.Application["sConn"]; But I'm not quite sure how to retrieve reference to the HttpContext from code in class library... Constructor for HttpContext requires a HttpWorkerRequest, which is of type System.Web.Hosting.SimpleWorkerRequest. First, I don't know how to get at it. QUESTION 2: Can I do this instead: string sConn = ((HttpContext) this.context).Application["sConn"]; myaspxpage.aspx namespace .. { Page_Load(..) { someName.MyComponent oManager = new someName.MyComponent(this.Request); //QUESTION: Is it necessary for me to pass WorkerRequest object as argument to constructor? Also, is "this.Request" of type "WorkerRequest"? I prefer not to supply Request/Reponse object to component constructor - first it's cleaner, secondly, the component will run in process of the ASPNET application, we can "probably" retrieve the objects from library code, right? //This is yet another alternative, equally clumsy: someName.MyComponent oManager(this.Request, this.Response); } } Signature of HttpContext is: public HttpContext(HttpRequest, HttpResponse); public HttpContext(HttpWorkerRequest); HttpWorkerRequest is of type: System.Web.Hosting.SimpleWorkerRequest HttpResponse is of type: System.Web.HttpResponse HttpRequest is of type: System.Web.HttpRequest Also, why "Response" or "Request" object, shouldn't a HttpContext be associated with a "HttpApplication" object instead? For instance, I don't see Application object is related to Response or Request object in any way. Thanks!

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      You can't create an HttpContext that represents a request - ASP.NET does this. If you need to get this for your application, you can either create an IHttpModule or IHttpHandler that gives you the HttpContext for a request, from which you can get the intrinsic objects (Request, Response, Server, User) which can get you the HttpApplication from the context. The Application property is there so you can access it from either modules or handlers. This is all covered pretty well in the SDK documentation for these interfaces and in several topics for create modules and handlers.

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups