Httpmodule 重新发送/重新创建请求

发布于 2025-01-06 08:25:27 字数 173 浏览 0 评论 0原文

我创建了一个 httpmodule,它获取用户 ip 信息并根据其 IP 将凭据附加到标头。但它会执行每个请求。我想监听 401 状态响应,然后运行 ​​ip 查找并重新发送请求。

我已准备就绪,可以捕获 401 错误,并将凭据附加到标头,但我无法弄清楚如何使用新标头重新发送请求。

可能转移或重写?

I have created an httpmodule that gets user ip information and append credentials to the header based on their IP. It does this every request though. I would like to listen for a 401 status response and then run the ip look up and resend the request through.

I have all the pieces in place, i can catch the 401 error, and attach credentials to a header, except i cannot figure out how to resend the request through with the new header.

Possibly transfer or rewrite?

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

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

发布评论

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

评论(1

安稳善良 2025-01-13 08:25:27

我不会详细说明为什么你选择这样的策略,因为这听起来不太优雅。无论如何,考虑到您的要求,我会在响应中设置两个 cookie,其中包含身份验证到期日期和哈希值来验证到期日期。然后将 301 重定向的响应更改为相同的 url。下次请求到达时,我已经设置了 cookie,您可以识别/验证并附加凭证标头。 Cookie 示例如下:

Set-Cookie: AuthExpiry=20/02/2012T12:30:12
Set-Cookie: AuthHash=38D67A30F9453E6A9A025A2395AC07EA198383A5

AuthHash 是通过连接 GetSHA(AuthExpiry+yourSecretPhrase) 生成的

I won't go into details why you've chosen such strategy as this doesn't sound very elegant. Anyway given your requirements I would set two cookies in the response, with authentication expiry date and hash value to validate expiry date. Then change the response to 301 redirect to the same url. Next time the request arrives I has set cookie which you identify/validate and attach the credential headers. Cookies example would be:

Set-Cookie: AuthExpiry=20/02/2012T12:30:12
Set-Cookie: AuthHash=38D67A30F9453E6A9A025A2395AC07EA198383A5

Where AuthHash is generated by concatenating GetSHA(AuthExpiry+yourSecretPhrase)

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