User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 422,633 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,752 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 853 | Replies: 5 | Solved
Reply
Join Date: Oct 2006
Location: somewhere in West-Africa
Posts: 202
Reputation: jamello is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

ASP.NET 2.0 equivalent Please

  #1  
Feb 11th, 2008
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!
Last edited by jamello : Feb 11th, 2008 at 2:28 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2008
Posts: 50
Reputation: a496761 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
a496761 a496761 is offline Offline
Junior Poster in Training

Re: ASP.NET 2.0 equivalent Please

  #2  
Feb 11th, 2008
Looks like you have it right... System.Security.Principal.GenericPrincipal

What error are you getting?
Reply With Quote  
Join Date: Oct 2006
Location: somewhere in West-Africa
Posts: 202
Reputation: jamello is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

Re: ASP.NET 2.0 equivalent Please

  #3  
Feb 12th, 2008
Originally Posted by a496761 View Post
Looks like you have it right... System.Security.Principal.GenericPrincipal

What error are you getting?


I am yet to get any error The point is that I cannot find or create the generic principal objects mainly because I cannot reference the objects by the usage of the "using" clause at the top of the global.asax file. So I repeat, How do I include this code or how do I make the generic principal objects available for use in the global.asax file.

I do hope I am clearer.
Thanks
Reply With Quote  
Join Date: Oct 2006
Location: somewhere in West-Africa
Posts: 202
Reputation: jamello is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

Re: ASP.NET 2.0 equivalent Please

  #4  
Feb 12th, 2008
Originally Posted by a496761 View Post
Looks like you have it right... System.Security.Principal.GenericPrincipal

What error are you getting?


I am yet to get any error The point is that I cannot find or create the generic principal objects mainly because I cannot reference the objects by the usage of the "using" clause at the top of the global.asax file. So I repeat, How do I include this code or how do I make the generic principal objects available for use in the global.asax file.

I do hope I am clearer.
Thanks
Reply With Quote  
Join Date: Feb 2008
Posts: 50
Reputation: a496761 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
a496761 a496761 is offline Offline
Junior Poster in Training

Re: ASP.NET 2.0 equivalent Please

  #5  
Feb 12th, 2008
Sorry, I misunderstood. You can always fully qualify the names (use System.Security.Principal.GenericPrincipal anywhere that you are currently using GenericPrincipal). Otherwise, this article explains why you can't use the "using" key and offers a workaround: http://rossnelson.blogspot.com/2005/...aspnet-20.html

I hope this helps!
Reply With Quote  
Join Date: Oct 2006
Location: somewhere in West-Africa
Posts: 202
Reputation: jamello is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

Re: ASP.NET 2.0 equivalent Please

  #6  
Feb 13th, 2008
Originally Posted by a496761 View Post
Sorry, I misunderstood. You can always fully qualify the names (use System.Security.Principal.GenericPrincipal anywhere that you are currently using GenericPrincipal). Otherwise, this article explains why you can't use the "using" key and offers a workaround: http://rossnelson.blogspot.com/2005/...aspnet-20.html

I hope this helps!


Yes, This was what I did eventually to move ahead. Thanks all the same. It was quite nice of you...

And the blogpost you suggested? SUPER DUPER!!!!
Gracias A Plenty!!!!!!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 3:10 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC