CredentialCache和NetworkCredentia

CredentialCache和NetworkCredentia

本文介绍了Windows 7操作系统.Net Windows服务中的CredentialCache和NetworkCredential的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 问题 访问NetworkCredentials,Windows服务应用程序Problem in accessing NetworkCredentials, Windows service Application请参阅以下代码: CredentialCacheCredentialCache credentialCache = null ;credentialCache = null;   credentialCache = new CredentialCache (); credentialCache = newCredentialCache(); networkCredential =networkCredential = (UserId.Trim(),Password.Trim( )); credentialCache.Add(credentialCache.Add( WebRequest.Credentials = credentialCache;WebRequest.Credentials=credentialCache; : 在行   networkCredential = new NetworkCredential (UserId.Trim(),Password.Trim());得到错误"对象引用未设置为对象的实例"  仅在窗口7操作系统中,并且在Windows XP中正常工作, 请帮助我。Please Help me out. 先谢谢。    推荐答案 UserId 或密码为空。 在调用 string.Trim()方法之前,你应该检查字符串是否为空。UserId or Password is null.You should check if string is null before you call string.Trim() method.示例: string username = null; string password = null; if (!string.IsNullOrEmpty(UserId)) { username = UserId.Trim(); } if (!string.IsNullOrEmpty(Password)) { password = Password.Trim(); } CredentialCache credentialCache = new CredentialCache(); NetworkCredential networkCredential = new NetworkCredential(username, password); credentialCache.Add(new System.Uri(url),"BASIC",networkCredential); 这篇关于Windows 7操作系统.Net Windows服务中的CredentialCache和NetworkCredential的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-24 13:00