使用 asp.net,如何重定向用户并同时更改 POST 数据?

发布于 2024-08-06 02:45:14 字数 471 浏览 16 评论 0原文

我有一个单点登录解决方案,这意味着用户将登录到一个网站并被重定向到另一个网站。当我重定向用户时,我想传递一个可用于验证用户身份验证状态的密钥。

我读过的大多数单点登录示例都显示,传递加密密钥的登录站点具有查询字符串值。我认为这不是一个很好的解决方案,因为它不是非常 REST-ful 或任何你想称呼它的东西。相反,我想在 POST 数据中传递加密密钥。因此,当用户登录时,他们会发布到另一个网址。

不幸的是,我(尚)不知道如何使用Response.RedirectServer.Transfer来做到这一点。我认为 Response.Redirect 在重定向时会传递相同的 POST 数据。

有人知道如何在 asp.net 中重定向网站用户,在重定向时更改 POST 数据吗?

(额外问题:重定向时可以将 GET 更改为 POST 吗?)

I have a single sign-on solution, meaning that the user will login to one site and be redirected to another. When I redirect the user I want to pass along a key that can be used to verify the user's authentication status.

Most of the examples of single sign-on I read show the login site passing the encrypted key has a query string value. I don't think this is a very good solution because it's not very REST-ful or whatever you want to call it. Instead I'd like to pass the encrypted key in the POST data. So when the user logins in, they are POSTing to another url.

Unfortunately I don't know (yet) how to do this with the Response.Redirect or Server.Transfer. I think Response.Redirect passes the same POST data along when it redirects.

Does someone know how to redirect a website user in asp.net, changing the POST data while redirecting?

(bonus question: can you change a GET to a POST while redirecting?)

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

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

发布评论

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

评论(1

爱的故事 2024-08-13 02:45:14

Server.Transfer 能够在转换过程中维护表单数据(POST 值),因为它本质上是将用户发送的相同请求传输到新端点。

Request.Redirect 无法持久保存 POST 数据,因为重定向本质上是将响应发送回最终用户,表示“改为转到此处”。然后,客户端向该新端点发起新请求。客户端不会在第二个单独的请求中重新提交 POST 数据。

然而,单独的 POST 和 GET 都或多或少是 RESTful 的——两者都是数据字符串,只是请求的部分略有不同。拥有干净、无查询字符串的 URL 可能“看起来是 REST-y”,但它只是装饰性的。

这是两种不同方法如何工作的图表。正如您所看到的,在重定向情况下,根本不可能更改 POST 数据,因为它由客户端负责形成对目标 URL 的新请求;在 Transfer 案例中,这样做是没有意义的(即使技术上可行),因为如果您确实需要将附加数据传递给新处理程序,您可以自己这样做:

替代文本 http://rexmorgan.net/rr_vs_st.jpg

Server.Transfer has the ability to maintain form data (POST values) in transition, because it is essentially transferring the same request sent by the user to a new endpoint.

Request.Redirect cannot persist POST data because a redirect is essentially sending a response back to the end-user which says "go here instead". The client then initiates a new request to that new endpoint. The client does not re-submit the POST data on the second, separate request.

However, neither POST nor GET alone are more or less RESTful - both are strings of data, just in slightly different parts of the request. Having clean, querystring-less URLs might "look REST-y", but it is cosmetic.

Here's a diagram of how the two different approaches work. As you can see, in the Redirect case, changing the POST data simply isn't possible because it's in the client's hands to form the new request to the target URL; and in the Transfer case, it makes no sense to (even if it was technically possible) because if you do need to pass additional data to the new handler, you can do so yourself:

alt text http://rexmorgan.net/rr_vs_st.jpg

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