Asp.net: Replace GenericPrincipal

前端 未结 1 1602
情深已故
情深已故 2021-02-09 18:48

I was wondering what the best way is to replace the genericPrincipal with my own CustomGenericPrincipal.

At the moment I have something like this but I aint sure if it\'

1条回答
  •  误落风尘
    2021-02-09 19:26

    You are missing a subtle detail, the thread.

        Context.User = Thread.CurrentPrincipal = new CustomPrincipal....
    

    Will get you where you need to go.

    Also I notice you mention that you need to only replace the principal. If this is the case, you can simply reuse the FormsIdentity that has already been constructed for you as shown below.

        Context.User = Thread.CurrentPrincipal = new CustomPrincipal(Context.User.Identity /*, add roles here if desired*/ );
    

    0 讨论(0)
提交回复
热议问题