What's the difference between retrieving WindowsPrincipal from WindowsIdentity and Thread.CurrentPrincipal?

前端 未结 3 1667
你的背包
你的背包 2021-02-05 10:12

I am trying to work out why attribute based security isn\'t working as I\'d expect in WCF and I suspect it might have something to do with the following:

AppDoma         


        
3条回答
  •  野性不改
    2021-02-05 10:43

    I admit it's a rather ugly workaround, but if all else fails you could replace:

    principal = (WindowsPrincipal)Thread.CurrentPrincipal;
    

    with something like

    principal = new WindowsPrincipal(new WindowsIdentity(Thread.CurrentPrincipal.Identity.Name));
    

    If that doesn't work, it will probably at least be instructive in showing where things are going wrong.

    But I can't imagine it failing, since it does exactly the same thing (where it is relevant) as the line that worked: I assume Thread.CurrentPrincipal.Identity.Name is "ksarfo".

提交回复
热议问题