如何将具有 URI 的 link 转发到具有相同 URI 的另一个 link

how to forward a link with URI to another link with the same URI

我的程序使用用户名和密码将用户定向到一个网页。例如。 http://example.html?username=username&password=password.

现在我在 asp.net 中创建了另一个页面,我想要 example.html 上的一些代码将 link 重定向到 http://example.aspx?username=username&password=password

所以我想要的是从第一个 url 获取 URI 并通过附加 URI 将其定向到新的 url。

有什么建议吗?

您可以通过

获取完整的查询字符串
window.location.search

请参阅 this 了解更多信息。使用它,您可以提取参数,将它们附加到新的 URL,并呈现 link,或设置

window.location = "example.aspx" + window.location.search

我相信搜索带有“?”,但我可能错了。我认为这是一个例子;请注意,将密码作为明文通过查询字符串传递不是一个好习惯,尤其是在您未使用 HTTPS 的情况下。当涉及敏感信息时,通常建议执行 POST 操作,而不是使用查询字符串的 GET 操作。

使用window.location.search获取“?”之后的所有内容。然后你可以直接使用这个 java 脚本行来引导新的 aspx 页面。

window.location = "example.aspx" + window.location.search