How to get current HttpRequest?

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

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?
 
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
}
 
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
 
Back
Top