尝试了太多的自动重定向。 [英] Too many automatic redirections were attempted.

查看:124
本文介绍了尝试了太多的自动重定向。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我有一个控制台应用程序,我正在尝试连接到我的网站并发回一个身份验证cookie。如果我将url直接粘贴到浏览器中,则返回cookie很好但是当我尝试通过控制台应用程序连接时,我收到以下错误尝试了太多的自动重定向。当我点击客户端时.OpenRead(sUrl)



任何帮助都非常苛刻



控制台应用程序

Hey guys, I have a console application which I'm trying to connect to my website and send back an authentication cookie. If I paste the url directly in to the browser the cookie is returned just fine but when I try connect through the console application I get the following error "Too many automatic redirections were attempted." when I hit the client.OpenRead(sUrl)

Any help is very much apreciated

Console Application

string sUrl = "http://localhost/CreateCookie.aspx?UserName=" + username + "&Password=" + password;

           client.Headers.Add("user-agent",
               "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

           using (Stream data = client.OpenRead(sUrl))
           {
               using (StreamReader reader = new StreamReader(data))
               {
                   strCookie = reader.ReadToEnd();
               }
           }





网页



Web Page

Dim sUserName As String = Request.QueryString("UserName")
Dim sPassword As String = Request.QueryString("Password")

Dim ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, sUserName, DateTime.Now, DateTime.Now.AddDays(30), False, _
"SignalR", FormsAuthentication.FormsCookiePath)
'/ Encrypt the ticket.
Dim encTicket As String = FormsAuthentication.Encrypt(ticket)
' // Create the cookie.
Response.Write(encTicket)
Response.End()

推荐答案

你应该使用HttpWebRequest和cookie容器:



You should probably use an HttpWebRequest and a cookie container:

var client = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(sUrl);
client.CookieContainer = new System.Net.CookieContainer();


On Page指令也使用
On Page directive also use
EnableSessionState="False"



它对我有用。


It works for me.


hi,



i有这个错误但得到了一个简单的修复

你不需要所有的代码,所有你需要做的就是在你的应用程序的开头下载像这样的cookie(抱歉,但我使用VB :)但转换非常简单)





i had this error but got a simple fix
you don't need all that code, all you need is to do is in the beginning of your application download the cookie like this (sorry but i work with VB :) but is pretty simple to convert)

[your application namespace].Application.GetCookie(New Uri("https://[site]"))







来自葡萄牙的问候

Gandum




Greetings from Portugal
Gandum


这篇关于尝试了太多的自动重定向。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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