以编程方式登录网站并将用户重定向到登录页面?

发布于 2024-08-25 09:43:20 字数 207 浏览 4 评论 0原文

现在,我让公司的所有员工使用公司 ID、用户名和密码登录外部网站。我们正在尝试将其集成到 Intranet 门户中,该门户应提供对此网站的无缝访问,而无需用户输入这些凭据。

有什么方法可以以编程方式执行此操作(.NET C#)?与屏幕抓取非常相似,我可以模拟适当的 POST 操作,然后将用户重定向到登录页面吗?

任何帮助表示赞赏。

谢谢。


Right now, I have all the employees of my company login to an external website using the company id, username and a password. We are trying to integrate it into an intranet portal which should provide seamless access to this website without requiring the user to enter these credentials.

Is there any way of doing this programmatically (.NET C#)? Very similar to screenscraping, Can I simulate the appropriate POST action and then redirect the user to the logged in page?

Any help is appreciated.

Thanks.


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅听莫相离 2024-09-01 09:43:20

您可以在页面中创建一个

,使用相同的 action= 属性镜像外部站点的登录表单,然后使用 Javascript 填充并提交它。

请注意,这需要您将用户的密码发送到浏览器,这永远不是一个好主意。

You can make a <form> in your page that mirrors the external site's login form with the same action= attribute, then fill put and submit it using Javascript.

Note that this requires that you send the user's password to the browser, which is never a good idea.

美人迟暮 2024-09-01 09:43:20

您当然可以发布到外部网站,当您将用户重定向到那里时,棘手的一点就会出现,因为我认为会有 cookie 限制。

您也许可以使用 Javascript 做一些事情,使客户端浏览器使用正确的凭据直接发布到第三方,请查看 jQuery 的 Post 命令。

假设外部网站以某种方式维护与 cookie 的会话,问题是,您的公司网站无法设置 cookie,除非来自它自己的域,而第 3 方网站无法读取除来自它自己的域的 cookie,所以您无法将 cookie 转移或传递给您的用户。

You can certainly post to the external website, the tricky bit will come when you redirect the user there, because there'll be cookies restrictions I think.

You might be able to do something with Javascript that makes the Client browser post directly to the third party with the correct credentials, look into jQuery's Post command.

Assuming that the external website maintains sessions with cookies in some way, the problem is, your company website can't set a cookie, except from it's own domain, and the 3rd party website can't read cookies except from it's own domain, so you can't transfer or pass the cookie across to your users.

蓦然回首 2024-09-01 09:43:20

该技术的名称是单点登录。没有一种方法可以做到这一点,但新兴标准称为 SAML。这需要两个部分(发起者和目标网站)的参与,因此它可能超出了您当前的权限。

就像这里提到的其他两个答案一样,您可以直接将格式化请求发布到登录脚本的操作,但我可以根据经验告诉您,该解决方案将很脆弱,也就是说,它会在目标网站创建的第二秒中崩溃任何改变。

最好的办法是联系目标网站的管理员,询问他们是否有SSO(单点登录)解决方案。

The name for this technique is Single Sign-On. There's no one way to do it, but the emerging standard is called SAML. This requires participation on both parts (the originator and target website), so it's probably beyond your current purview.

Like the other two answers have mentioned here, you can post a formatted request directly to the action of the login script, but I can tell you from experience that that solution will be brittle, that is, it will shatter the second the target website makes any changes.

Your best bet is to contact the administrator of the target website and ask if they have an SSO (Single Sign On) solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文