1

我基本上是在尝试通过模拟登录用户从我的 Web 应用程序访问网络共享资源。我遵循了这个例子 [ http://msdn.microsoft.com/en-us/library/ms998351.aspx#paght000023_impersonatingbyusingwindowsidentity],这里作者没有提到演员阵容失败。当我进行该演员表时,我得到了无法进行演员表的运行时异常。以前有人遇到过这种问题吗?

非常感谢您的指导或建议!

谢谢

  WindowsIdentity winId = (WindowsIdentity)HttpContext.Current.User.Identity;
WindowsImpersonationContext ctx = null;
try
{
  // Start impersonating
  ctx = winId.Impersonate();
  // Now impersonating
  // Access resources using the identity of the authenticated user
}
// Prevent exceptions from propagating
catch
{
}
finally
{
  // Revert impersonation
  if (ctx != null)
  ctx.Undo();
}
// Back to running under the default ASP.NET process identity
4

2 回答 2

1

什么是真正在你的Identity?也许它是通用身份或其他身份 - 不是您认为的 Windows 身份:

string typeOfIdentity = HttpContext.Current.User.Identity.GetType().FullName;

这里的结果是什么?这可能会为您提供有关您在这里真正处理的内容的更多信息。

马克

于 2009-06-11T20:35:01.147 回答
0

我不确定你想用模拟做什么,所以很难确切地告诉你如何去做,但是你的 web 应用程序中的 User 对象等效于 System.Security.Principal.IPrincipal 对象,而不是 WindowsPrincipal 对象。

同样,User.Identity 是 IIdentity 而不是 WindowsIdenity 对象。

你能发布更多关于你想要做什么的信息吗?

于 2009-06-11T20:33:07.830 回答