大佬教程收集整理的这篇文章主要介绍了resharper – 可以WindowsIdentity.GetCurrent()返回null吗?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
WindowsIdentity windowsIdentity = new WindowsIdentity(WindowsIdentity.GetCurrent().Token);
我查看了MSDN文档,但没有看到任何提及.此外,它没有意义,因为如果您运行可执行文件,则必须先登录.
这只是一个ReSharper搜索模式吗?
GetCurrent:
public static WindowsIdentity GetCurrent() { return WindowsIdentity.GetCurrenTinternal(TokenAccessLevels.MaximumAllowed,falsE); }
GetCurrenTinternal:
internal static WindowsIdentity GetCurrenTinternal(TokenAccessLevels desiredAccess,bool threadOnly) { int errorCode = 0; bool flag; SafeTokenHandle currentToken = WindowsIdentity.GetCurrentToken(desiredAccess,threadOnly,out flag,out errorCodE); if (currentToken != null && !currentToken.IsInvalid) { WindowsIdentity windowsIdentity = new WindowsIdentity(); windowsIdentity.m_safeTokenHandle.Dispose(); windowsIdentity.m_safeTokenHandle = currentToken; return windowsIdentity; } if (threadOnly && !flag) { return null; } throw new SecurityException(Win32Native.Getmessage(errorCodE)); }
因为从GetCurrent调用时ThreadOnly总是为false,而且currentToken必须对另一个return语句有效,我不认为你有获得一个空的WindowsIdentity的风险.
以上是大佬教程为你收集整理的resharper – 可以WindowsIdentity.GetCurrent()返回null吗?全部内容,希望文章能够帮你解决resharper – 可以WindowsIdentity.GetCurrent()返回null吗?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。