加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – ASP.NET中的NetworkCredential错误

发布时间:2020-12-15 08:28:00 所属栏目:百科 来源:网络整理
导读:我正在尝试使用NetworkCredential类通过ASP.NET访问网页.但是我继续使用以下消息获得异常System.Security.Cryptography.CryptographicException:句柄无效 下面是关于我如何调用该函数的代码.任何帮助是极大的赞赏. C#: System.Net.WebClient client = new
我正在尝试使用NetworkCredential类通过ASP.NET访问网页.但是我继续使用以下消息获得异常System.Security.Cryptography.CryptographicException:句柄无效

下面是关于我如何调用该函数的代码.任何帮助是极大的赞赏.

C#:

System.Net.WebClient client = new System.Net.WebClient();
client.Credentials = new System.Net.NetworkCredential("Admin","Nimda");

堆栈跟踪

[CryptographicException: The handle is invalid.
]

System.Security.SecureString.ProtectMemory() +154
   System.Security.SecureString.InitializeSecureString(Char* value,Int32 length) +170
   System.Security.SecureString..ctor(Char* value,Int32 length) +65
   System.Net.SecureStringHelper.CreateSecureString(String plainString) +6181188
   System.Net.NetworkCredential..ctor(String userName,String password) +64

解决方法

好吧这有点尴尬 – 我看了一下,错误是你的Windows配置….某处.

抛出异常的代码部分实际上是对advapi32.dll中的函数的互操作调用,具体来说:

int status = Win32Native.SystemFunction040(this.m_buffer,(uint) (this.m_buffer.Length * 2),0);
if (status < 0)
{
    throw new CryptographicException(Win32Native.LsaNtStatusToWinError(status));
}
this.m_encrypted = true;

呼叫:

[ReliabilityContract(Consistency.WillNotCorruptState,Cer.Success),DllImport("advapi32.dll",CharSet=CharSet.Unicode,SetLastError=true)]
internal static extern int SystemFunction040([In,Out] SafeBSTRHandle pDataIn,[In] uint cbDataIn,[In] uint dwFlags);

那将返回错误代码,导致您的异常.

如果您在工作场所,您可能希望与您的系统管理员/网络人员交谈,以查看您的本地策略中是否存在可能导致故障的任何内容.
否则,我会看到如果禁用防病毒/禁用防火墙/关闭任何第三方代理软件会发生什么.

基本上,任何覆盖默认网络功能的东西.
此外,可能值得检查您有所有最新的Windows更新,并且您没有任何病毒或恶意软件感染.

对不起,我不能更具体,但我不相信这是.Net /编程错误.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读