以编程方式获取.ASPXAUTH Cookie值 [英] Get the .ASPXAUTH cookie value programmatically

查看:86
本文介绍了以编程方式获取.ASPXAUTH Cookie值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过编程方式获取.ASPXAUTH值。



示例我使用自己的凭据(POST)登录到网站,然后读取响应。 .it不会在我用来跟踪会话的CookieContainer中返回.APSXAUTH。和帖子?



以下是我要做的工作:




  • 将HTTP GET发送到页面。读取_VIEWSTATE等值。

  • 发送HTTP POST到登录页面。它包括登录信息。

  • 服务器将302响应(重定向)发送到某个默认页面。



所以我一直认为可能有比这更好的方法了。跟踪会话:

  CookieContainer _cookieJar = new CookieContainer(); 

HttpWebRequest请求=(HttpWebRequest)WebRequest.Create(_url);
request.CookieContainer = _cookieJar;


解决方案

所以总结答案:



如果您尝试通过自己的应用程序以程序形式登录基于表单的身份验证网站,请确保遵循跟踪cookie的步骤。



首先创建一个初始 GET 请求,然后再执行随后的 POST 请求, postback。请求和响应应以这种方式制定:

  HttpWebRequest request =(HttpWebRequest)WebRequest.Create(_url) ; 
request.CookieContainer = _cookieJar;
HttpWebResponse httpsResponse =(HttpWebResponse)request.GetResponse();

CookieContainer 类按预期处理Cookie 。



如果您的回复使用Gzip编码,则只需添加以下行:

  request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; 

在调用 request.GetResponse()之前



希望这可以帮助某个人。


Is there a way to get the .ASPXAUTH value programmatically.

Example I login to a website with my own credentials (POST) and then read the response...it does not return the .APSXAUTH in the CookieContainer that I use to track the session.

Anyone has a clue how can I get it and send it with the subsequent gets and posts?

[EDIT] Here's what I do to be more specific:

  • send a HTTP GET to a page. read values like _VIEWSTATE etc.
  • send a HTTP POST to the Login page. It includes the login information.
  • The server sends a 302 response (redirect) to some Default page. The forms authentication cookie is supposed to be included but it's not.

So I was thinking that there might be a better way than this to track session:

CookieContainer _cookieJar = new CookieContainer();

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url);
request.CookieContainer = _cookieJar;

解决方案

So the summarize the answer:

If you're trying to login programatically on a Forms based authentication website trough your own application make sure you follow the steps you take that track the cookies.

First create a initial GET request, and then do the subsequential POST requests that will do the postback.The request and the responses should be formulated in this way:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url);
request.CookieContainer = _cookieJar;
HttpWebResponse httpsResponse = (HttpWebResponse)request.GetResponse();

The CookieContainer class handles the cookies as expected.

And if your response is encoded with Gzip just include the following line:

request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

before you call request.GetResponse()

Hope this helps someone out there.

这篇关于以编程方式获取.ASPXAUTH Cookie值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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