如何使用Windows登录凭据在Webbrowser中自动登录

时间:2019-04-07 19:38:03

标签: windows google-chrome internet-explorer

我有一个网站(内部应用程序),该网站要求使用与Windows登录凭据相同的用户名和密码。从技术上讲,单点登录是不可能的。我有大约1000个客户,每次都需要输入其帐户详细信息,因此我想使之自动化。是否可以编写脚本,使用户单击其桌面上的快捷方式并使用Windows凭据在网站上自动登录?谢谢你的想法。

1 个答案:

答案 0 :(得分:0)

如果您的站点托管在IIS服务器上以供内部使用,则可以尝试参考以下示例,以帮助您解决问题。

代码:

// Ensure Directory Security settings for default web site in IIS is "Windows Authentication".
string url = "http://localhost";
// Create a 'HttpWebRequest' object with the specified url. 
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
// Assign the credentials of the logged in user or the user being impersonated.
myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials;
// Send the 'HttpWebRequest' and wait for response.            
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
Console.WriteLine("Authentication successful");
Console.WriteLine("Response received successfully");

DefaultCredentials代表运行应用程序的当前安全上下文的系统凭据。对于客户端应用程序,这些通常是运行该应用程序的用户的Windows凭据(用户名,密码和域)。对于ASP.NET应用程序,默认凭据是已登录用户或被模拟用户的用户凭据。

参考:

CredentialCache.DefaultCredentials Property

相关问题