ASP.NET 2.0 equivalent Please

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2006
Posts: 216
Reputation: jamello is an unknown quantity at this point 
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

ASP.NET 2.0 equivalent Please

 
0
  #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
  1. //included at the top of the global.asax file
  2. using System.Web.Security;
  3. using System.Security.Principal;


In the Application_AuthenticateRequest event handler I add the following code

  1. // Extract the forms authentication cookie
  2. string cookieName = FormsAuthentication.FormsCookieName;
  3. HttpCookie authCookie = Context.Request.Cookies[cookieName];
  4.  
  5. if(null == authCookie)
  6. {
  7. // There is no authentication cookie.
  8. return;
  9. }
  10.  
  11. FormsAuthenticationTicket authTicket = null;
  12. try
  13. {
  14. authTicket = FormsAuthentication.Decrypt(authCookie.Value);
  15. }
  16. catch(Exception ex)
  17. {
  18. return;
  19. }
  20.  
  21. if (null == authTicket)
  22. {
  23. // Cookie failed to decrypt.
  24. return;
  25. }
  26.  
  27. // When the ticket was created, the UserData property was assigned a
  28. // pipe delimited string of role names.
  29. string[] roles = authTicket.UserData.Split(new char[]{'|'});
  30.  
  31. // Create an Identity object
  32. FormsIdentity id = new FormsIdentity( authTicket );
  33.  
  34. // This principal will flow throughout the request.
  35. GenericPrincipal principal = new GenericPrincipal(id, roles);
  36. // Attach the new principal object to the current HttpContext object
  37. Context.User = principal;

Version 2.0
All is well until you get to

  1. //you cannot include at the top of the global.asax file
  2. using System.Web.Security;
  3. using System.Security.Principal;
  4.  
  5. // This principal will flow throughout the request - you cannot find the genericprincipal object!.
  6. GenericPrincipal principal = new GenericPrincipal(id, roles);
  7. // Attach the new principal object to the current HttpContext object
  8. 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

  1. //you cannot include at the top of the global.asax file
  2. using System.Web.Security;
  3. using System.Security.Principal;



Pls any help would be appreciated!
Last edited by jamello; Feb 11th, 2008 at 3:28 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 62
Reputation: a496761 is an unknown quantity at this point 
Solved Threads: 4
a496761 a496761 is offline Offline
Junior Poster in Training

Re: ASP.NET 2.0 equivalent Please

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

What error are you getting?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 216
Reputation: jamello is an unknown quantity at this point 
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

Re: ASP.NET 2.0 equivalent Please

 
0
  #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 Quick reply to this message  
Join Date: Oct 2006
Posts: 216
Reputation: jamello is an unknown quantity at this point 
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

Re: ASP.NET 2.0 equivalent Please

 
0
  #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 Quick reply to this message  
Join Date: Feb 2008
Posts: 62
Reputation: a496761 is an unknown quantity at this point 
Solved Threads: 4
a496761 a496761 is offline Offline
Junior Poster in Training

Re: ASP.NET 2.0 equivalent Please

 
0
  #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 Quick reply to this message  
Join Date: Oct 2006
Posts: 216
Reputation: jamello is an unknown quantity at this point 
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

Re: ASP.NET 2.0 equivalent Please

 
0
  #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 Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC