How to get current HttpRequest?

Discussion in 'ASP .Net' started by Jeff, Jan 22, 2009.

  1. Jeff

    Jeff Guest

    hi

    ASP.NET 3.5

    My webproject's BLL has a static method which I want to perform all the
    reading of the QueryString. (the static method reads and decrypt the value).
    Currently this method take a HttpRequest as input parameter, so when using
    this method in the .aspx.cs files I send in the Request as parameter. But I
    hope maybe I get reference to current HttpRequest without sending it in as
    parameter.

    any suggestion?
    Jeff, Jan 22, 2009
    #1
    1. Advertising

  2. Jeff

    Jeff Guest

    I suppose it's solved

    I'm using this code now:
    HttpContext.Current.Request.QueryString
    Jeff, Jan 22, 2009
    #2
    1. Advertising

  3. Jeff

    sloan Guest

    Re: I suppose it's solved

    You might want to add a null check just to make sure

    if ( null == System.Web.HttpContext.Current ) // Add a reference to
    System.Web.dll
    { //Non Web Environment
    }

    or

    if ( null != System.Web.HttpContext.Current ) // Add a reference to
    System.Web.dll
    { //Web Environment
    }




    "Jeff" <> wrote in message
    news:%...
    > I'm using this code now:
    > HttpContext.Current.Request.QueryString
    >
    >
    >
    >
    >
    >
    sloan, Jan 22, 2009
    #3
  4. Jeff

    George Guest

    Me personally would advice against that.
    Here are the options that is much better (from design point of view in my
    opinion) and the one you choose will depend on actual functionality you
    need.

    1. If it's a true BLL (Busness layer) class then make it accept
    NameValueCollection as a parameter. Then you can call you Business class
    from anywere even Desktop application.
    And pass Request.QueryString cause it's derived from a NameValueCollection.

    2. If all you need is a small helper function (then do not call it a BLL).
    Derive your page(pages) from your own clsStandardPage (which in turn derived
    from System.Web.UI.Pages) and simply add this as a method. Then any page
    that need to use that helper function will call it as a memeber.


    George

    "Jeff" <> wrote in message
    news:...
    > hi
    >
    > ASP.NET 3.5
    >
    > My webproject's BLL has a static method which I want to perform all the
    > reading of the QueryString. (the static method reads and decrypt the
    > value). Currently this method take a HttpRequest as input parameter, so
    > when using this method in the .aspx.cs files I send in the Request as
    > parameter. But I hope maybe I get reference to current HttpRequest
    > without sending it in as parameter.
    >
    > any suggestion?
    >
    George, Jan 22, 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. Greg Reevosh via .NET 247

    HTTPRequest and JAVA Servlet

    Greg Reevosh via .NET 247, Oct 17, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    577
    Greg Reevosh via .NET 247
    Oct 17, 2004
  2. Dino Chiesa [Microsoft]

    Re: HTTPRequest and JAVA Servlet

    Dino Chiesa [Microsoft], Oct 27, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    473
    Dino Chiesa [Microsoft]
    Oct 27, 2004
  3. Greg Reevosh via .NET 247

    HTTPRequest and JAVA Servlet

    Greg Reevosh via .NET 247, Oct 31, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    399
    Greg Reevosh via .NET 247
    Oct 31, 2004
  4. John Saunders

    Re: HTTPRequest and JAVA Servlet

    John Saunders, Nov 17, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    442
    John Saunders
    Nov 17, 2004
  5. Kevin
    Replies:
    2
    Views:
    32,202
    Hermit Dave
    Dec 13, 2003
Loading...

Share This Page