Httpmodule 重新发送/重新创建请求
我创建了一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不会详细说明为什么你选择这样的策略,因为这听起来不太优雅。无论如何,考虑到您的要求,我会在响应中设置两个 cookie,其中包含身份验证到期日期和哈希值来验证到期日期。然后将 301 重定向的响应更改为相同的 url。下次请求到达时,我已经设置了 cookie,您可以识别/验证并附加凭证标头。 Cookie 示例如下:
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:
Where AuthHash is generated by concatenating GetSHA(AuthExpiry+yourSecretPhrase)