How to get current HttpRequest?

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?
 
S

sloan

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
}
 
G

George

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top