【发布时间】:2010-12-12 13:55:58
【问题描述】:
这是我在命令提示符下运行的一个简单的控制台应用程序:
using System;
using System.Threading;
namespace Test
{
internal class Runner
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine(Thread.CurrentPrincipal.GetType().Name);
Console.WriteLine(Thread.CurrentPrincipal.Identity.Name);
}
}
}
输出是 'GenericPrincipal' 和空字符串作为身份名称。为什么运行时构造 GenericPrincipal 而不是 WindowsPrincipal?我如何强制它从启动进程的安全令牌(在我的例子中为 cmd.exe)构造WindowsPrincipal?
【问题讨论】:
-
查询
WindowsIdentity current = WindowsIdentity.GetCurrent();会得到什么?? -
它按我的预期返回我当前的 Windows 身份。那么构建和附加主体是我的责任吗?或者有一种方法可以在配置文件中指定它,就像在 ASP.NET 或 WCF 应用程序中的安全设置一样?
标签: .net security windows-7 .net-4.0 principal