Hello All

I am trying to convert a code sample that I have working in VB.NET to C#

The Problem is that in the Application_AuthenticateRequest Event in
Global.asax.cs the cookie is not being evalated , The Sample I have working
is from

[url]http://www.codeproject.com/dotnet/SecurityModelDotNet.asp[/url]

Thanks
Stuart


----------------------------------------------------------------------------------
Below is a sample of my C# Code

protected void WindowsAuthentication_OnAuthenticate(object
sender,WindowsAuthenticationEventArgs e)
{
//Check for the existence of the cookie. If it exists then Authentication
Ticket has
//already been created.

if(null == Context.Request.Cookies["authCookie"])
{

//Get User ID from Windows Authenticated Event
string userId = (UserGroupInfo.LoginIdStripDomain(e.Identity.Name) );

//Get User Role List
//string roleList = "ADMIN|POWER_USER|USER";

// Create a authentication ticket w/Role List.
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1,
e.Identity.Name,DateTime.Now, DateTime.Now.AddMinutes(60),
false, roleList);

// Encrpt the ticket before setting the cookie value
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);

// Create a cookie and add the encrypted ticket to the cookie as data.
HttpCookie authCookie = new
HttpCookie(FormsAuthentication.FormsCookieName,enc ryptedTicket);

// Add the cookie to the outgoing cookies collection.
Response.Cookies.Add(authCookie);
}
}

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{

string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];

if(!(null == authCookie))
{
//HttpCookie authCookie = Context.Request.Cookies["authCookie"];
FormsAuthenticationTicket authTicket =
FormsAuthentication.Decrypt(authCookie.Value);

// Create an Identity object
GenericIdentity userIdentity = new GenericIdentity(authTicket.Name);

string[] roles = authTicket.UserData.Split(new char[]{'|'});
GenericPrincipal principal = new GenericPrincipal(userIdentity, roles);

// Attach the new principal object to the current HttpContext object
HttpContext.Current.User = principal;
}
}