473,434 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

How to access HttpContext from standalone class

I'm getting "'HttpContext' does not exist in the class or namespace
'System.Web'" from trying to build (with Microsoft Development
Environment 2003, ver. 7.1.3088, .NET Framework 1.1, ver. 1.1.4322)
something like this:

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Text;

namespace A
{
public class A
{
public A()
{
// get value from HTTP header
NameValueCollection collection;
collection = System.Web.HttpContext.Current.Request.ServerVaria bles;

// etc., etc.
}
}
}
What I would like to do is to create a standalone class "A", which can
be used in an aspx file like so:

<%@ Import Namespace="A" %>
<script language="C#" runat="server">
void Page_Load( Object Sender, EventArgs e ) {
A a = new A();
// etc, etc.
}

I feel pretty stupid staring at a message like that, after having
checked
http://msdn.microsoft.com/library/de...classtopic.asp...

Nov 17 '05 #1
4 2251
ju****@firma.tele.dk wrote:
I'm getting "'HttpContext' does not exist in the class or namespace
'System.Web'" from trying to build (with Microsoft Development
Environment 2003, ver. 7.1.3088, .NET Framework 1.1, ver. 1.1.4322)
something like this:

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Text;

namespace A
{
public class A
{
public A()
{
// get value from HTTP header
NameValueCollection collection;
collection = System.Web.HttpContext.Current.Request.ServerVaria bles;

// etc., etc.
}
}
}
What I would like to do is to create a standalone class "A", which can
be used in an aspx file like so:

<%@ Import Namespace="A" %>
<script language="C#" runat="server">
void Page_Load( Object Sender, EventArgs e ) {
A a = new A();
// etc, etc.
}

I feel pretty stupid staring at a message like that, after having
checked
http://msdn.microsoft.com/library/de...classtopic.asp...


Is that class "A" defined in a separate class-library project?
Did you reference the System.Web dll there?
Hans Kesting
Nov 17 '05 #2
Yes (as in File->New->Project->Class Library).

Not besides fully qualifying HttpContext. But it makes no difference if
I include a "using System.Web;" statement. Can I reference System.Web
in another way?

Nov 17 '05 #3
jul...@firma.tele.dk:

"Not besides fully qualifying HttpContext. But it makes no difference
if
I include a "using System.Web;" statement. Can I reference System.Web
in another way? "

I think what Hans means is, did you add a reference to System.Web.dll
in your class library project?

Jason Gorman
http://www.parlezuml.com
UML tutorials for Java & .NET

Nov 17 '05 #4
No - but I should have. It is now working. Thanks for the help, both!

Nov 17 '05 #5

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

Similar topics

2
by: Phil Ten | last post by:
Hello, I am working on a .NET C++ project based on the "Class Library (.NET)" wizard of Visual Studio .NET 2003. I would like to know if my .NET component is running in a ASP.NET page (.apsx...
3
by: MarkMurphy | last post by:
In a barebones website with one page, checking HttpContext.Current.Request.UserLanguages.Length in Page_Load of an ASPX page in the VS IDE in codebehind shows a value of 1. Then when I refresh...
6
by: SteveS | last post by:
Hello All. I have an asp.net application with 3 different assemblies. They are like this: 1) Assembly: PublicSite (This contains the website UI) Root namespace: PublicSite 2) Assembly:...
2
by: Stu | last post by:
Hi, If I try to access an application variable from a class I get the error 'Name Application is not declared'. Is ther any (fairly simple) way of getting round this or do I have to pass the...
1
by: GarDavis | last post by:
When the ASP.Net application ends, the Application_OnEnd() method in Global.asax is called. This method calls a utility in a class library to dump information about the ending application. The...
3
by: xzzy | last post by:
A. I need to access: System.Web.HttpContext.Current.Cache but get this error: "Object reference not set to an instance of the object" B. System.Web.HttpContext.Current.Cache is accessible...
17
by: Joe | last post by:
Hello All; I can't access System.Web.HttpServerUtility from within a Class. I want to have access to MapPath. What I get are three options. They are: AspNetHostingPermission...
3
by: damianarielfernandez | last post by:
Hi group, I read a lot about this problem and all the same answers appears...Implement the IRequireSessionState or IReadOnlySessionState interface...but the same problem arrays'...null session. ...
0
by: bharathreddy | last post by:
Here I will given an example on how to access the session, application and querystring variables in an .cs class file. Using System.Web.HttpContext class. 1) For accesing session variables :...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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
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
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,...
0
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
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
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.