小编c4n*_*c4n的帖子

每个请求的C#WebClient NTLM身份验证启动

考虑一个简单的C#.NET Framework 4.0应用程序,它:

  • 使用WebClient
  • 使用NTLM进行身份验证(在IIS 6.0和IIS 7.5服务器上测试)
  • 使用DownloadString()多次从URL检索字符串

这是一个工作正常的样本:

using System;
using System.Net;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string URL_status = "http://localhost/status";

            CredentialCache myCache = new CredentialCache();
            myCache.Add(new Uri(URL_status), "NTLM", new NetworkCredential("username", "password", "domain"));

            WebClient WebClient = new WebClient();
            WebClient.Credentials = myCache;

            for (int i = 1; i <= 5; i++)
            {
                string Result = WebClient.DownloadString(new Uri(URL_status));
                Console.WriteLine("Try " + i.ToString() + ": " + Result);
            }

            Console.Write("Done");
            Console.ReadKey();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

问题:

启用跟踪时,我发现NTLM身份验证不会持久存在. …

.net c# authentication ntlm webclient

13
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

authentication ×1

c# ×1

ntlm ×1

webclient ×1