Namespaces not found

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I am trying to create a class for my Authentication and want to add it to
the HTTP pipeline. But when I create my project and build it I get the
following errors:

The type or namespace name 'Web' does not exist in the class or namespace
'System' (are you missing an assembly reference?)
The type or namespace name 'IHttpModule' could not be found (are you missing
a using directive or an assembly reference?)
The type or namespace name 'HttpApplication' could not be found (are you
missing a using directive or an assembly reference?)

How can they not be there?

System.Web should be there.

I am using VS 2002 and don't have problems with my other projects.

Here is my code:

**********************************************************************

using System;
using System.Security.Principal;
using System.Web;
using System.Web.Security;
using System.Diagnostics;
using System.Web.HttpApplication;

namespace AuthModule
{
public class SetIdentity: IHttpModule
{
public SetIdentity()
{
}

public void Init(HttpApplication context)
{
context.AuthenticateRequest +=
(new EventHandler(this.Application_AuthenticateRequest));
}

private void Application_AuthenticateRequest(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;

// Get the authentication cookie
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = context.Request.Cookies[cookieName];
if(authCookie==null)
return;

// Get the authentication ticket
// and rebuild the principal & identity
FormsAuthenticationTicket authTicket =
FormsAuthentication.Decrypt(authCookie.Value);
string[] roles = authTicket.UserData.Split(new Char [] {'|'});
GenericIdentity userIdentity = new GenericIdentity(authTicket.Name);
GenericPrincipal userPrincipal =
new GenericPrincipal(userIdentity, roles);
context.User = userPrincipal;
}

public void Dispose()
{
}
}
}
***************************************************************

Thanks,

Tom
 
Greg Young said:
Does the project have a reference to System.Web?

That is what is confusing.

Isn't that what I did?

using System;
using System.Security.Principal;
using System.Web;
Cheers,

Greg
tshad said:
I am trying to create a class for my Authentication and want to add it to
the HTTP pipeline. But when I create my project and build it I get the
following errors:

The type or namespace name 'Web' does not exist in the class or namespace
'System' (are you missing an assembly reference?)
The type or namespace name 'IHttpModule' could not be found (are you
missing
a using directive or an assembly reference?)
The type or namespace name 'HttpApplication' could not be found (are you
missing a using directive or an assembly reference?)

How can they not be there?

System.Web should be there.

I am using VS 2002 and don't have problems with my other projects.

Here is my code:

**********************************************************************

using System;
using System.Security.Principal;
using System.Web;
using System.Web.Security;
using System.Diagnostics;
using System.Web.HttpApplication;

namespace AuthModule
{
public class SetIdentity: IHttpModule
{
public SetIdentity()
{
}

public void Init(HttpApplication context)
{
context.AuthenticateRequest +=
(new EventHandler(this.Application_AuthenticateRequest));
}

private void Application_AuthenticateRequest(Object source, EventArgs
e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;

// Get the authentication cookie
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = context.Request.Cookies[cookieName];
if(authCookie==null)
return;

// Get the authentication ticket
// and rebuild the principal & identity
FormsAuthenticationTicket authTicket =
FormsAuthentication.Decrypt(authCookie.Value);
string[] roles = authTicket.UserData.Split(new Char [] {'|'});
GenericIdentity userIdentity = new GenericIdentity(authTicket.Name);
GenericPrincipal userPrincipal =
new GenericPrincipal(userIdentity, roles);
context.User = userPrincipal;
}

public void Dispose()
{
}
}
}
***************************************************************

Thanks,

Tom
 
That is importing a namespace. That's not referencing. Only namespaces from
referenced assemblies can be imported. To do that: In VS pick up "Add
Reference" on top of "References" and choose System.Web.dll assembly.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


tshad said:
Greg Young said:
Does the project have a reference to System.Web?

That is what is confusing.

Isn't that what I did?

using System;
using System.Security.Principal;
using System.Web;
Cheers,

Greg
tshad said:
I am trying to create a class for my Authentication and want to add it to
the HTTP pipeline. But when I create my project and build it I get the
following errors:

The type or namespace name 'Web' does not exist in the class or
namespace
'System' (are you missing an assembly reference?)
The type or namespace name 'IHttpModule' could not be found (are you
missing
a using directive or an assembly reference?)
The type or namespace name 'HttpApplication' could not be found (are you
missing a using directive or an assembly reference?)

How can they not be there?

System.Web should be there.

I am using VS 2002 and don't have problems with my other projects.

Here is my code:

**********************************************************************

using System;
using System.Security.Principal;
using System.Web;
using System.Web.Security;
using System.Diagnostics;
using System.Web.HttpApplication;

namespace AuthModule
{
public class SetIdentity: IHttpModule
{
public SetIdentity()
{
}

public void Init(HttpApplication context)
{
context.AuthenticateRequest +=
(new EventHandler(this.Application_AuthenticateRequest));
}

private void Application_AuthenticateRequest(Object source, EventArgs
e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;

// Get the authentication cookie
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = context.Request.Cookies[cookieName];
if(authCookie==null)
return;

// Get the authentication ticket
// and rebuild the principal & identity
FormsAuthenticationTicket authTicket =
FormsAuthentication.Decrypt(authCookie.Value);
string[] roles = authTicket.UserData.Split(new Char [] {'|'});
GenericIdentity userIdentity = new
GenericIdentity(authTicket.Name);
GenericPrincipal userPrincipal =
new GenericPrincipal(userIdentity, roles);
context.User = userPrincipal;
}

public void Dispose()
{
}
}
}
***************************************************************

Thanks,

Tom
 
No, that is just specifying that you would like to be able to use the
namespace ..

right click on your project, select "Add Reference" in the dialog that pops
up select System.Web

Your code should then compile.

Cheers,

Greg
tshad said:
Greg Young said:
Does the project have a reference to System.Web?

That is what is confusing.

Isn't that what I did?

using System;
using System.Security.Principal;
using System.Web;
Cheers,

Greg
tshad said:
I am trying to create a class for my Authentication and want to add it to
the HTTP pipeline. But when I create my project and build it I get the
following errors:

The type or namespace name 'Web' does not exist in the class or
namespace
'System' (are you missing an assembly reference?)
The type or namespace name 'IHttpModule' could not be found (are you
missing
a using directive or an assembly reference?)
The type or namespace name 'HttpApplication' could not be found (are you
missing a using directive or an assembly reference?)

How can they not be there?

System.Web should be there.

I am using VS 2002 and don't have problems with my other projects.

Here is my code:

**********************************************************************

using System;
using System.Security.Principal;
using System.Web;
using System.Web.Security;
using System.Diagnostics;
using System.Web.HttpApplication;

namespace AuthModule
{
public class SetIdentity: IHttpModule
{
public SetIdentity()
{
}

public void Init(HttpApplication context)
{
context.AuthenticateRequest +=
(new EventHandler(this.Application_AuthenticateRequest));
}

private void Application_AuthenticateRequest(Object source, EventArgs
e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;

// Get the authentication cookie
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = context.Request.Cookies[cookieName];
if(authCookie==null)
return;

// Get the authentication ticket
// and rebuild the principal & identity
FormsAuthenticationTicket authTicket =
FormsAuthentication.Decrypt(authCookie.Value);
string[] roles = authTicket.UserData.Split(new Char [] {'|'});
GenericIdentity userIdentity = new
GenericIdentity(authTicket.Name);
GenericPrincipal userPrincipal =
new GenericPrincipal(userIdentity, roles);
context.User = userPrincipal;
}

public void Dispose()
{
}
}
}
***************************************************************

Thanks,

Tom
 
Back
Top