WindowsIdentity winId =(WindowsIdentity)HttpContext.Current.User.Identity;如何使演员表有效;目前失败了 [英] WindowsIdentity winId = (WindowsIdentity)HttpContext.Current.User.Identity; How to make this cast work; currently it is failing

查看:71
本文介绍了WindowsIdentity winId =(WindowsIdentity)HttpContext.Current.User.Identity;如何使演员表有效;目前失败了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上是通过模拟已登录的用户来尝试从Web应用程序访问网络共享资源.我遵循了此示例[ http://msdn.microsoft.com/zh-cn/library/ms998351.aspx#paght000023_impersonatingbyusingwindowsidentity] ,此处作者没有提及强制转换失败.当我执行该转换时,我遇到了无法进行转换的运行时异常.有人遇到过此类问题吗?

I am basically trying to access the network share resources from my Web Application by impersonating the logged in user. I followed this example [http://msdn.microsoft.com/en-us/library/ms998351.aspx#paght000023_impersonatingbyusingwindowsidentity], here the writer does not mention about the cast failing. When i did that cast, I got the runtime exception that the cast cannot be made. Anyone has gone through this kind of issues before?

指导或建议受到高度赞赏!

Guidance or suggestions are higly appreciated!

谢谢

  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

推荐答案

我不确定您要使用假冒方式做什么,因此很难 告诉您确切的操作方法,但是您的Web应用程序中的User对象是 等价于System.Security.Principal.IPrincipal对象,而不是 WindowsPrincipal对象.

I am not sure what you're trying to do with impersonation so it's hard to tell you exactly how to do it but the User object in your web app is equivelent to a System.Security.Principal.IPrincipal object and not a WindowsPrincipal object.

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

Likewise, the User.Identity is an IIdentity and not a WindowsIdenity object.

您可以发布更多您想做的事情吗?

Can you post more about what you're trying to do?

这篇关于WindowsIdentity winId =(WindowsIdentity)HttpContext.Current.User.Identity;如何使演员表有效;目前失败了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆