我基本上是在尝试通过模拟登录用户从我的 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