Hi there ladies and gentlemen!
I have this code that works in ASP.NET 1.1 but I could not find its equivalent in v 2.0. I had expected it to work having the usual backward compatibility preached by microsoft in mind. But I am yet to succeed. The code 'translation' worked until the need to program in the global.asax file.
The problem is about role based authentication of users using 'forms' authentication. In v1.1 the portion where the need arises to construct GenericPrincipal and formsIdentity objects works well but I cannot find the reference to the GenericPrincipal objects in v2.0
This is version 1.1 code snippets
//included at the top of the global.asax file
using System.Web.Security;
using System.Security.Principal;
In the Application_AuthenticateRequest event handler I add the following code
// Extract the forms authentication cookie
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
if(null == authCookie)
{
// There is no authentication cookie.
return;
}
FormsAuthenticationTicket authTicket = null;
try
{
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
}
catch(Exception ex)
{
return;
}
if (null == authTicket)
{
// Cookie failed to decrypt.
return;
}
// When the ticket was created, the UserData property was assigned a
// pipe delimited string of role names.
string[] roles = authTicket.UserData.Split(new char[]{'|'});
// Create an Identity object
FormsIdentity id = new FormsIdentity( authTicket );
// This principal will flow throughout the request.
GenericPrincipal principal = new GenericPrincipal(id, roles);
// Attach the new principal object to the current HttpContext object
Context.User = principal;
Version 2.0
All is well until you get to
//you cannot include at the top of the global.asax file
using System.Web.Security;
using System.Security.Principal;
// This principal will flow throughout the request - you cannot find the genericprincipal object!.
GenericPrincipal principal = new GenericPrincipal(id, roles);
// Attach the new principal object to the current HttpContext object
Context.User = principal;
OR
Maybe the question should be where or how do we include the following the in global.asax file in v2.0
//you cannot include at the top of the global.asax file
using System.Web.Security;
using System.Security.Principal;
Pls any help would be appreciated!