How do you get credentials (NetworkCredential) of currently logged in user?

前端 未结 6 2106
夕颜
夕颜 2021-02-05 02:01

I\'m writing some code to utilise a 3rd party component, and I need to supply an object which implements ICredentials when I start to use it.

If I write the following...

6条回答
  •  一个人的身影
    2021-02-05 02:53

    You need to do impersonation, for example:

        System.Security.Principal.WindowsImpersonationContext impersonationContext;
    impersonationContext = 
        ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();
    
    //Insert your code that runs under the security context of the authenticating user here.
    
    impersonationContext.Undo();
    

    http://support.microsoft.com/kb/306158

    Or you can use web.config:

    
    

提交回复
热议问题