windows - 如何使用 Windows 登录凭据在 Web 浏览器中自动登录
问题描述
我有一个网站(内部应用程序),它需要用户名和密码,这与他们的 Windows 登录凭据相同。单点登录在技术上是不可能的。我有大约 1000 个客户每次都需要输入他们的帐户详细信息,所以我想自动执行此操作。是否可以编写用户单击桌面上的快捷方式并使用网站上的 Windows 凭据自动登录的脚本?感谢您的任何想法。
解决方案
如果您的站点托管在 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 应用程序,默认凭据是登录用户或被模拟用户的用户凭据。
参考:
推荐阅读
- node.js - 如何在 React 中处理输入的“Enter”
- apache-kafka - Confluent 4.1.0 -> KSQL:STREAM-TABLE 连接 -> 表数据为空
- qt - 组件的 QML 工具提示
- r - 选择 data.table 的所有行,其中变量是列名,其值为 TRUE
- haskell - 从 Coq 中提取时可以自动添加 Haskell 导入语句吗?
- java - Java spring 错误持久性导入不起作用
- python - 提取两个分隔符之间的字符串
- javascript - 在谷歌饼图中将笔画宽度更改为 2
- php - SQL innerjoin 将整数转换为文本
- c - 在 c 中克隆 avl 树时出现 BUS 错误