.NET System.Net.HttpWebRequest和放大器;身份验证cookie [英] .Net System.Net.HttpWebRequest & Authentication Cookies

查看:101
本文介绍了.NET System.Net.HttpWebRequest和放大器;身份验证cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果以下是可能的:

I would like to know if the following is possible:

作为一个ASP.Net页面请求的pageLoad的部分:

As part of the PageLoad of an ASP.Net page request:


  • 使用HttpWebRequest的(POST)做出一个窗体身份验证的请求
    不同的Web应用程序的网页

  • 检查响应,看是否认证成功(身份如果验证cookie已设置)

  • 如果失败,则完成ASP.Net页面请求,这将显示一个消息,说不能自动登录或一些这样的东西

  • 如果成功的话,而不是完成ASP.Net页面的生命周期中,使用的Response.Write从HttpWebRequest的回响应发送到浏览器
  • (因此基本上是从HttpWebRequest的显示网页)
  • Use HttpWebRequest (POST) to make a request to a forms authentication webpage of a different web application
  • Examine the response to see if the authentication succeeded (identifiable if an authentication cookie has been set)
  • If it fails, then finish the ASP.Net page request, which will display a message saying "couldn't auto-login" or some such thing
  • If success, then instead of completing the ASP.Net page lifecycle, use "Response.Write" to send the response from the HttpWebRequest back to the browser (thus essentially displaying the webpage from the HttpWebRequest)

如果上面是可能的,那么,有没有也有办法从HttpWebResponse转移验证cookie到请求浏览器?我的直觉是可能不是 - 但如果是这样的话,那怎么办代理服务器处理这样的事情?那是没有本质的他们在做什么?

If the above is possible, then, is there also a way to transfer the authentication cookie from the HttpWebResponse to the requesting browser? My gut feeling is probably not - but if this is the case, then how do proxy servers handle such things? Is that not essentially what they are doing?

感谢您的帮助。

推荐答案

您可以添加的的CookieContainer HttpWebRequest的。这将存储从响应收到任何cookie和如果附加了相同的cookie容器到下一个请求,它将这些Cookie发送备份到服务器。

You can add a CookieContainer to the HttpWebRequest. It will store any cookies received from the response and if you attach the same cookie container to the next request, it will send those cookies back up to the server.

您可以访问此的CookieContainer对象的内容和发送者回你的客户使用Response.Cookies。

You can access the contents of this CookieContainer object and send those back to your client using Response.Cookies.

这篇关于.NET System.Net.HttpWebRequest和放大器;身份验证cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆