How to access HttpContext from standalone class

  • Thread starter Thread starter julian
  • Start date Start date
J

julian

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.ServerVariables;

// 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/d.../html/frlrfsystemwebhttpcontextclasstopic.asp...
 
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.ServerVariables;

// 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/d.../html/frlrfsystemwebhttpcontextclasstopic.asp...

Is that class "A" defined in a separate class-library project?
Did you reference the System.Web dll there?


Hans Kesting
 
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?
 
(e-mail address removed):

"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
 
Back
Top