2010-04-27 79 views
1

我在写一个sharepoint web部分。它将日志写入文件(使用StreamWriter)。但是,日志仅写入其托管Web部件的服务器上的帐户是管理员的用户。我想要检测哪个帐户(可能不是通过使用SPUser)正在执行Web部件的代码,以便我可以为较少特权的用户生成日志。那可能吗?如何检测哪个Windows帐户正在运行.net应用程序?

感谢

回答

1

这段代码会为你提供用户所属的组。

var id = System.Security.Principal.WindowsIdentity.GetCurrent(); 
IdentityReferenceCollection irc = id.Groups; 
foreach (IdentityReference ir in irc) 
    Console.WriteLine(ir.Value); 
1

有一些方法都到相同的结果:我觉得一个

  • Request.LogonUserIdentity
  • HttpContext.Request.LogonUserIdentity
  • Page.User.Identity

从那里必须在SharePoint服务器上的作品。哪一项工作将取决于你想要包含代码的上下文,你应该在你需要的地方放置一个断点,并且在监视窗口中看到上面的一个构造。如果有人在那里工作,您会收到System.Security.Principal.WindowsPrincipal类型的对象,它可以为您提供所需的所有内容。例如,名称属性是用户名。 Groups属性是SecurityIdentifier的列表,它对应于用户所属的组。可以使用NTAccount类将SecurityIdentifier转换为名称。 (参见例如,I have a SID of a user account, and I want the SIDs of the groups it belongs to

相关问题