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