Setting Thread.CurrentPrincipal with a custom principal object.

Last post 08-06-2007 11:04 PM by XiaoYong Dai – MSFT. 2 replies.

Sort Posts:

  • Setting Thread.CurrentPrincipal with a custom principal object.

    08-03-2007, 2:26 AM
    • Member
      point Member
    • swmiller
    • Member since 08-03-2007, 6:17 AM
    • Posts 3

    I have an ASP.NET 2.0 web application that is using Forms Authentication.  I was trying to create a custom principal object by inheriting from GenericPrincipal and setting Thread.CurrentPrincipal to the new custom principal object.  I was setting Thread.CurrentPrincipal inside the FormsAuthentication_OnAuthenticate method in the Global.asax file.  Things compile and run however when I set a break point and look at the principal type stored in Thread.CurrentPrincipal it is not my custom principal object but a principal boject called RolePrinciple.  Needless to say I'm a bit confused.  Can anyone tell me if I'm setting this correctly?

     Thanks, Steve.

  • Re: Setting Thread.CurrentPrincipal with a custom principal object.

    08-03-2007, 3:31 AM
    Answer
    • Contributor
      2,278 point Contributor
    • ziqbalbh
    • Member since 02-26-2007, 12:58 PM
    • Lahore, Pakistan
    • Posts 359

    Hi,

    From your description I have concluded that you create an instance of GenericPrincipal, and assign it Three.CurrentPrincipal (correct?). If you do that, then it means that your generic principal will hold same type of principal which was in Thread.CurrentPrincipal. For this I recommend that you create a new principal object and pass it required data capturing it from either Thread.CurrentPrincipal or Request and then assign that instance to Thread.CurrentPrincipal again. You can create your own custom principal class, which can handle all other related items for you.
     

    Zafar Iqbal
    VP Technology
    Hansvits
    http://ziqbalbh.com

    ** Please mark as ANSWER if my reply helped you
  • Re: Setting Thread.CurrentPrincipal with a custom principal object.

    08-06-2007, 11:04 PM
    Answer

    Hi

    Here you can get more information on creating a new instance of the security principal

    http://www.4guysfromrolla.com/webtech/121901-1.2.shtml

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
    Best Regards
    XiaoYong Dai
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Page 1 of 1 (3 items)