下面的代码将向 IIS 基本授权站点发布请求。并使用 Windows 凭据成功登录该站点。但我需要做的是将其转换为在浏览器中打开网站,就像打开一个带有 target="null" 的新超链接一样。
回顾一下,如何将 WebRequest 发布到新的浏览器选项卡?或者如何将 CredentialCache 发送到新的 URL 请求?
var request = WebRequest.Create(testURL);
SetBasicAuthHeader(request, "username", "password", testURL);
var response = request.GetResponse();
}
public void SetBasicAuthHeader(WebRequest request, String userName, String userPassword, String testURL)
{
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add(new System.Uri(testURL), "Basic", new NetworkCredential(userName, userPassword, "domain"));
request.Credentials = credentialCache;
request.PreAuthenticate = true;
}