473,508 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing HttpContext in ClassLibrary?

hi
i have a vs solution in which there are 2 projects
class library representing Security services and another one is web
application project.
i need to access http context in a static method in a class of Security
Services project.
how can this be done.

thanks
-sami
Feb 23 '07 #1
4 27972
HttpContext.Current

George

"Sami Rehman" <sa*********@4D.orgwrote in message
news:eB**************@TK2MSFTNGP04.phx.gbl...
hi
i have a vs solution in which there are 2 projects
class library representing Security services and another one is web
application project.
i need to access http context in a static method in a class of Security
Services project.
how can this be done.

thanks
-sami

Feb 23 '07 #2

which should be avoided when possible, but obviously isn't always.

at the very least you could do a null check:

if (HttpContext.Current == null)
{
//either fallback to something or throw some exception
//throw new NotImplementedException("This function can only be called
within a webrequest-context for now");
}
Don't remember if you need to reference System.Web.dll, I'd assume so.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"George Ter-Saakov" <gt****@cardone.comwrote in message
news:uW*************@TK2MSFTNGP05.phx.gbl...
HttpContext.Current

George

"Sami Rehman" <sa*********@4D.orgwrote in message
news:eB**************@TK2MSFTNGP04.phx.gbl...
>hi
i have a vs solution in which there are 2 projects
class library representing Security services and another one is web
application project.
i need to access http context in a static method in a class of Security
Services project.
how can this be done.

thanks
-sami

Feb 23 '07 #3
but the problem is i have got MyCompany.MyProject.Security.dll reference in
MyCompany.MyProject.WebUI.dll which is the right way i guess because
Security's services will be consumed by WebUI..... it is however in Security
that i need to access the session object.

the error that i get at compile time is that 'The name 'HttpContext'' does
not exist in the current context", which is true since Security is another
project.

can i access the httpcontext object without passing it as an argument to a
class in Security component??


"Karl Seguin [MVP]" <ka********@removeopenmymindremovemetoo.andmenetwr ote
in message news:37**********************************@microsof t.com...
>
which should be avoided when possible, but obviously isn't always.

at the very least you could do a null check:

if (HttpContext.Current == null)
{
//either fallback to something or throw some exception
//throw new NotImplementedException("This function can only be called
within a webrequest-context for now");
}
Don't remember if you need to reference System.Web.dll, I'd assume so.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"George Ter-Saakov" <gt****@cardone.comwrote in message
news:uW*************@TK2MSFTNGP05.phx.gbl...
>HttpContext.Current

George

"Sami Rehman" <sa*********@4D.orgwrote in message
news:eB**************@TK2MSFTNGP04.phx.gbl...
>>hi
i have a vs solution in which there are 2 projects
class library representing Security services and another one is web
application project.
i need to access http context in a static method in a class of Security
Services project.
how can this be done.

thanks
-sami


Feb 26 '07 #4
Yes, and george told you how..you simply need to do

System.Web.HttpContext current = System.Web.HttpContext.Current;

you'll need to add a reference to System.Web as well, but that shouldn't
cause any problems.

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Sami Rehman" <sa*********@4D.orgwrote in message
news:uV**************@TK2MSFTNGP06.phx.gbl...
but the problem is i have got MyCompany.MyProject.Security.dll reference
in MyCompany.MyProject.WebUI.dll which is the right way i guess because
Security's services will be consumed by WebUI..... it is however in
Security that i need to access the session object.

the error that i get at compile time is that 'The name 'HttpContext'' does
not exist in the current context", which is true since Security is another
project.

can i access the httpcontext object without passing it as an argument to a
class in Security component??


"Karl Seguin [MVP]" <ka********@removeopenmymindremovemetoo.andmenet >
wrote in message
news:37**********************************@microsof t.com...
>>
which should be avoided when possible, but obviously isn't always.

at the very least you could do a null check:

if (HttpContext.Current == null)
{
//either fallback to something or throw some exception
//throw new NotImplementedException("This function can only be called
within a webrequest-context for now");
}
Don't remember if you need to reference System.Web.dll, I'd assume so.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"George Ter-Saakov" <gt****@cardone.comwrote in message
news:uW*************@TK2MSFTNGP05.phx.gbl...
>>HttpContext.Current

George

"Sami Rehman" <sa*********@4D.orgwrote in message
news:eB**************@TK2MSFTNGP04.phx.gbl...
hi
i have a vs solution in which there are 2 projects
class library representing Security services and another one is web
application project.
i need to access http context in a static method in a class of Security
Services project.
how can this be done.

thanks
-sami

Feb 26 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1963
by: Will Waggoner | last post by:
Ok, I've been hung up on this issue for quite some time now and I would like some help in getting it to work. I think this may be a setup issue but I'd like to ask your eminences first. Here's...
3
3738
by: Michael Iantosca | last post by:
I have a custom attribute that I attach to certain pages in my application and I want to inspect each page request as it is made to see if the custom attribute is attached to the underlying page...
2
1266
by: pc | last post by:
I am writing a a Web Form where I am making calls to a separate class which performs several routines I use on several pages. The routines all require access to the Request, Response, Application, or...
5
5034
by: coollzh | last post by:
who can tell the detailed difference of: HttpRuntime, Context, HttpContext.Current sometimes, we can use Context Object instead of HttpContext.Current; sometimes, we can user HttpRuntime...
0
981
by: ABN | last post by:
Hi I have prepared a new setup of my web application on a machine having Framework 1.0 with SP2 When I am trying to access any of the .aspx page, following exception gets raised Exception...
5
10355
by: Victor Jones | last post by:
I had a question about accessing HttpContext.User in global.asax. I was trying to access HttpContext.User in Application_BeginRequest() which had a null value as opposed to containing a valid...
4
5337
by: Mat | last post by:
Hi, I've stumbled onto a problem when using the caching object in ASP.Net. I'm placing a static dataset to the cache as the data only changes once a day. Whilst writing to the cache I'm using...
3
7643
by: Jim Lewis | last post by:
I have read several things that state accessing a Web Service through a Query String should work. However, when I try to execute http://localhost/webservice1/service1.asmx/HelloWorld I get the...
3
8874
by: Madhur | last post by:
Hello I am delivering an asp.net 2.0 application to my customer. I need to know, If I need to check for the condition of HttpContext.Current to be null in my business logic. I have extensively...
0
7227
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7127
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.