简体   繁体   English

网络凭据未保存在CredentialCache中

[英]Network Credentials not saving in CredentialCache

I have to assign the username and password from credential cache to Httpwebrequest.When i assign to cache it is working but when assigning to Webrequest from cache it shows null. 我必须将凭据缓存中的用户名和密码分配给Httpwebrequest。当我分配给缓存时它正在工作,但是当从缓存分配给Webrequest时它显示为空。 Where i'm wrong? 我哪里错了?

string strServer = "";
        strServer = "http://servername/";
        Uri uri = new Uri(strServer);
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
        CredentialCache cache = new CredentialCache();  
        cache.Add(new Uri(strServer), "Basic", new System.Net.NetworkCredential("username", "password","Domain"));
        cache.Add(new Uri(strServer), "Digest", new System.Net.NetworkCredential("username", "password","Domain"));
        request.Credentials = cache;


Hello, You just need to retrieve the credential from the cache, and then add it to the web request, example bellow: 您好,您只需要从缓存中检索凭证,然后将其添加到Web请求中,例如下面的示例:

    cache.Add(new Uri(strServer), "Basic", new System.Net.NetworkCredential("username", "password","Domain"));
    cache.Add(new Uri(strServer), "Digest", new System.Net.NetworkCredential("username", "password","Domain"));    

    NetworkCredential  currentCredentials= cache.GetCredential(new Uri(strServer), "Basic");  //Get specific credential
    request.Credentials = currentCredentials; //Allocate credential

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 credentialcache.defaultcredentials返回错误的用户凭证 - credentialcache.defaultcredentials returning wrong user credentials 未知重定向时为HttpWebRequest.Credentials建立一个CredentialCache - Building a CredentialCache for HttpWebRequest.Credentials when redirects are uknown 将 CredentialCache 对象分配给 HttpWebRequest.Credentials 在 Windows 通用应用程序中不起作用 - Assign CredentialCache object to a HttpWebRequest.Credentials in Windows Universal Apps don't work 没有代理时使用WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultNetworkCredentials是否有缺点? - Are there drawbacks to using WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultNetworkCredentials when there is no proxy? CredentialCache.DefaultCredentials 不遵守 dotnet core 2.2 的 IIS 应用程序池凭据 - CredentialCache.DefaultCredentials isn't respecting IIS App Pool Credentials with dotnet core 2.2 具有CredentialCache默认凭据的ASP.NET web.config连接字符串 - ASP.NET web.config connection string with CredentialCache default credentials 使用凭证的网络IO - Network IO using Credentials .NET中的CredentialCache和HttpWebRequest - CredentialCache and HttpWebRequest in .NET 具有凭据的网络路径的可用性检查 - Availability check of a network path with credentials Web应用程序,提示网络外的凭据并在网络上使用Windows凭据 - Web application that prompts credentials off network and uses Windows credentials on the network
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM