System.Net.HttpWebRequest与System.Web.HttpRequest [英] System.Net.HttpWebRequest vs. System.Web.HttpRequest

查看:103
本文介绍了System.Net.HttpWebRequest与System.Web.HttpRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释这两个班级之间的关系吗?我试图通过

HttpWebRequest将HttpRequest转移到一个新的位置,但我无法将我的头发转移到我的头发,但是我无法让我的会话xfer工作,可能是因为

cookie不兼容。我花了一个多星期试图获得

HWR与我的应用程序很好地集成,但我无法将会话转到

转移,而且它已经如果我试图消化

BCL中似乎不兼容的两个并行Web请求/响应类层次结构的逻辑,可能会让我更长一些彼此

System.Net/System.Web二分法并没有让事情变得更好,因为*没有*

我似乎可以使用,从凭证到cookie ,使用

当前请求,因为每个请求都有自己的并行支持

类。我正在使用以下内容来移动我的cookie,但是它显然是惨不忍睹(等待从

请求得到回复的时间):

System.Net.HttpWebRequest request =(System.Net.HttpWebRequest)

System.Net.HttpWebRequest.Create(uri.AbsoluteUri);


request.CookieContainer = new System.Net.CookieContainer();

request.CookieContainer.Add(HttpContext.Current.Re quest.Cookies);

foreach(字符串cookieName

System.Web.HttpContext.Current.Request.Cookies){

System.Web.HttpCookie cookie =

System.Web .HttpContext.Current.Request.Cookies [cookieName];

System.Net.Cookie bizarroCookie = new System.Net.Cookie();

bizarroCookie.Name = cookie。姓名;

bizarroCookie.Value = cookie.Value;

bizarroCookie.Domain = uri.Host;

request.CookieContainer.Add(bizarroCookie) ;


}

Could someone explain to me the relationship between these two classes? I
am ripping my hair out trying to divert an HttpRequest to a new location via
an HttpWebRequest, but I cannot get my session xfer to work, possibly due to
the cookies not being compatible. I''ve spent over a week trying to get the
HWR to integrate nicely with my app, but I cannot get the session to
transfer, and it''d probably take me even longer if I tried to digest the
logic of having two parallel web request/response class hierarchies in the
BCL which don''t seem to be compatible with one another. The
System.Net/System.Web dichotomy isn''t making things any better, as *nothing*
I seem to work with, from credentials on down to cookies, works with the
current request, because each one has its own parallel set of support
classes. I''m currently using the following to move my cookies over, but it
obviously fails miserably (times out waiting to get a response from the
request):
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)
System.Net.HttpWebRequest.Create(uri.AbsoluteUri);

request.CookieContainer = new System.Net.CookieContainer();
request.CookieContainer.Add(HttpContext.Current.Re quest.Cookies);
foreach (String cookieName in
System.Web.HttpContext.Current.Request.Cookies) {
System.Web.HttpCookie cookie =
System.Web.HttpContext.Current.Request.Cookies[cookieName];
System.Net.Cookie bizarroCookie = new System.Net.Cookie();
bizarroCookie.Name = cookie.Name;
bizarroCookie.Value = cookie.Value;
bizarroCookie.Domain = uri.Host;
request.CookieContainer.Add(bizarroCookie);

}

推荐答案

嗨Keith:


System.Web.HttpRequest是服务器上和内部使用的类一个

ASP.NET应用程序。它表示来自

客户端的*来电*请求。

System.Net.HttpWebRequest是一个用于制作*传出的类*

请求网络应用程序。


我怀疑你的cookie不会转移,因为这些域名不匹配。

Cookies是限于域名。例如,如果cookie的域名为
www.microsoft.com ,你不能只将cookie发送到

服务器msdn.microsoft.com(但是你可以发送一个带有域名的域名

of .microsoft.com服务器)。


-

Scott
http://www.OdeToCode.com/blogs/scott/

2005年2月21日星期一15:33 :25 -0600,Keith Patrick

< ri ******************* @ hotmail.com>写道:
Hi Keith:

System.Web.HttpRequest is a class used on the server and inside an
ASP.NET application. It represents the *incoming* request from a
client.

System.Net.HttpWebRequest is a class used to make an *outgoing*
request to a web application.

I suspect your cookies won''t transfer because the domains don''t match.
Cookies are restricted to a domain. If the domain of a cookie is
www.microsoft.com, for example, you can''t just send the cookie to the
server msdn.microsoft.com (but you could send a cookie with a domain
of .microsoft.com to both servers).

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Mon, 21 Feb 2005 15:33:25 -0600, "Keith Patrick"
<ri*******************@hotmail.com> wrote:
有人可以向我解释这两个类之间的关系吗?我试图通过HttpWebRequest将HttpRequest转移到新的位置,但我无法让我的会话xfer工作,可能是因为cookie不兼容。我已经花了一个多星期试图让
HWR与我的应用程序很好地集成,但是我无法将会话转移到
转移,如果我尝试的话,我可能会花更长的时间消化在BCL中具有两个并行的Web请求/响应类层次结构的逻辑,这些层次结构似乎彼此不兼容。
System.Net/System.Web二分法并没有让事情变得更好,因为*没什么*
我似乎可以使用,从凭证到cookie,与
一起使用当前请求,因为每个都有自己的并行支持类。我正在使用以下内容来移动我的cookie,但它很明显地失败了(等待从
请求得到响应的时间):
System.Net.HttpWebRequest请求=(System.Net.HttpWebRequest)
System.Net.HttpWebRequest.Create(uri.AbsoluteUri);

request.CookieContainer = new System.Net.CookieContainer();
request.CookieContainer.Add(HttpContext.Current.Re quest.Cookies);
foreach(
System.Web.HttpContext.Current.Request.Cookies中的String cookieName){
System.Web。 HttpCookie cookie =
System.Web.HttpContext.Current.Request.Cookies [cookieName];
System.Net.Cookie bizarroCookie = new System.Net.Cookie();
bizarroCookie.Name = cookie.Name;
bizarroCookie.Value = cookie.Value;
bizarroCookie.Domain = uri.Host;
请求。 CookieContainer.Add(bizarroCookie);

}
Could someone explain to me the relationship between these two classes? I
am ripping my hair out trying to divert an HttpRequest to a new location via
an HttpWebRequest, but I cannot get my session xfer to work, possibly due to
the cookies not being compatible. I''ve spent over a week trying to get the
HWR to integrate nicely with my app, but I cannot get the session to
transfer, and it''d probably take me even longer if I tried to digest the
logic of having two parallel web request/response class hierarchies in the
BCL which don''t seem to be compatible with one another. The
System.Net/System.Web dichotomy isn''t making things any better, as *nothing*
I seem to work with, from credentials on down to cookies, works with the
current request, because each one has its own parallel set of support
classes. I''m currently using the following to move my cookies over, but it
obviously fails miserably (times out waiting to get a response from the
request):
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)
System.Net.HttpWebRequest.Create(uri.AbsoluteUri) ;

request.CookieContainer = new System.Net.CookieContainer();
request.CookieContainer.Add(HttpContext.Current.Re quest.Cookies);
foreach (String cookieName in
System.Web.HttpContext.Current.Request.Cookies) {
System.Web.HttpCookie cookie =
System.Web.HttpContext.Current.Request.Cookies[cookieName];
System.Net.Cookie bizarroCookie = new System.Net.Cookie();
bizarroCookie.Name = cookie.Name;
bizarroCookie.Value = cookie.Value;
bizarroCookie.Domain = uri.Host;
request.CookieContainer.Add(bizarroCookie);

}






来自HttpRequest的域为null(路径为 ; /"),但如果我按原样复制那些

,当我调用

HttpWebRequest.CookieContainer.Add时,我会得到一个争论。我现在正在做的是在设置Cookie.Path = HttpCookie.Path时将Domain设置为

uri.Host。在超时(WebException,而不是TimeoutException)之后处理响应是
,并且每个cookie有2个

副本,所有这些都具有空域和/ "对于路径。

双重cookie只会出现问题 - 超时 - 当ASP.Net_SessionId cookie被复制时。我希望得到一些关于cookie /会话机制的理解比

标准文章(没有阅读IL :)更好的了解到哪里我可以弄清楚为什么

的cookie副本会过来,为什么复制的会话cookie是

导致线程挂起直到超时。


" Scott Allen" < SC *** @ nospam.odetocode.com>在消息中写道

news:bn ******************************** @ 4ax.com ...
The domain from the HttpRequest is null (path is "/"), but if I copy those
over as-is, I get an argumentexception when I call
HttpWebRequest.CookieContainer.Add. What I''m doing now is setting Domain to
uri.Host while setting Cookie.Path = HttpCookie.Path. The response is
processed after a timeout (WebException, not TimeoutException), and it has 2
copies of each cookie, all of them having a null Domain and "/" for path.
The double set of cookies is only being problematic - the timeouts - when
the ASP.Net_SessionId cookie is copied over. I''m hoping to get some kind of
understanding as to the cookie/session mechanism a bit better than the
standard articles (without reading IL :) ) to where I can figure out why the
copies of cookies are coming over, and why the copied session cookie is
leading to the thread hanging until timeout.

"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:bn********************************@4ax.com...
嗨Keith:

System.Web.HttpRequest是服务器上和ASP.NET应用程序内部使用的类。它表示来自
客户端的* incoming *请求。

System.Net.HttpWebRequest是一个用于向Web应用程序发出*传出*
请求的类。 />
我怀疑你的cookie不会转移,因为域名不匹配。
Cookie仅限于域名。例如,如果cookie的域名为
www.microsoft.com ,你不能只将cookie发送到
服务器msdn.microsoft.com(但你可以向两台服务器发送一个带有.microsoft.com域名的cookie)。

-
Scott
http:// www .OdeToCode.com / blogs / scott /

2005年2月21日星期一15:33:25 -0600,Keith Patrick
< ri *** ****************@hotmail.com>写道:
Hi Keith:

System.Web.HttpRequest is a class used on the server and inside an
ASP.NET application. It represents the *incoming* request from a
client.

System.Net.HttpWebRequest is a class used to make an *outgoing*
request to a web application.

I suspect your cookies won''t transfer because the domains don''t match.
Cookies are restricted to a domain. If the domain of a cookie is
www.microsoft.com, for example, you can''t just send the cookie to the
server msdn.microsoft.com (but you could send a cookie with a domain
of .microsoft.com to both servers).

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Mon, 21 Feb 2005 15:33:25 -0600, "Keith Patrick"
<ri*******************@hotmail.com> wrote:
有人可以向我解释这两个类之间的关系吗?我试图通过一个HttpWebRequest将HttpRequest转移到一个新的位置
,但我无法让我的会话xfer工作,可能是因为
到了
cookie不兼容。我已经花了一个多星期试图获得
HWR与我的应用程序很好地集成,但是我无法将会话转移到
转移,它甚至可能需要我如果我试图消化在BCL中具有两个并行的Web请求/响应类层次结构的逻辑,这些逻辑似乎并不相互兼容,那就更长了。
System.Net/System.Web二分法并没有让事情变得更好,因为
*没有*
我似乎可以使用,从凭证到cookie,适用于
当前请求,因为每个人都有自己的并行支持类。我正在使用以下内容来移动我的cookie,但是
它很明显地失败了(等待来自
请求的响应时间):
系统。 Net.HttpWebRequest request =
(System.Net.HttpWebRequest)
System.Net.HttpWebRequest.Create(uri.AbsoluteUri);

request.CookieContainer = new System.Net。 CookieContainer();

request.CookieContainer.Add(HttpContext.Current.Re quest.Cookies);
foreach(
System.Web.HttpContext.Current.Request中的String cookieName .Cookies){
System.Web.HttpCookie cookie =
System.Web.HttpContext.Current.Request.Cookies [cookieName];
System.Net.Cookie bizarroCookie = new System.Net。 Cookie();
bizarroCookie.Name = cookie.Name;
bizarroCookie.Value = cookie.Value;
bizarroCookie.Domain = uri.Host;
request.CookieContainer.Add(bizarroCookie);

}
Could someone explain to me the relationship between these two classes? I
am ripping my hair out trying to divert an HttpRequest to a new location
via
an HttpWebRequest, but I cannot get my session xfer to work, possibly due
to
the cookies not being compatible. I''ve spent over a week trying to get
the
HWR to integrate nicely with my app, but I cannot get the session to
transfer, and it''d probably take me even longer if I tried to digest the
logic of having two parallel web request/response class hierarchies in the
BCL which don''t seem to be compatible with one another. The
System.Net/System.Web dichotomy isn''t making things any better, as
*nothing*
I seem to work with, from credentials on down to cookies, works with the
current request, because each one has its own parallel set of support
classes. I''m currently using the following to move my cookies over, but
it
obviously fails miserably (times out waiting to get a response from the
request):
System.Net.HttpWebRequest request =
(System.Net.HttpWebRequest)
System.Net.HttpWebRequest.Create(uri.AbsoluteUri );

request.CookieContainer = new System.Net.CookieContainer();

request.CookieContainer.Add(HttpContext.Current.Re quest.Cookies);
foreach (String cookieName in
System.Web.HttpContext.Current.Request.Cookies ) {
System.Web.HttpCookie cookie =
System.Web.HttpContext.Current.Request.Cookies[cookieName];
System.Net.Cookie bizarroCookie = new System.Net.Cookie();
bizarroCookie.Name = cookie.Name;
bizarroCookie.Value = cookie.Value;
bizarroCookie.Domain = uri.Host;
request.CookieContainer.Add(bizarroCookie);

}



Hi Keith:


即使你设法将会话cookie复制过来 - 它

当到达不同的服务器甚至是
时都没有意义b不同ASP.NET应用程序中的同一服务器。会话是每个

应用程序和应用程序A没有知识或能力在应用程序B中映射

会话信息。


-

Scott
http:// www。 OdeToCode.com/blogs/scott/


< ri ******************* @ nospam.hotmail.com>写道:
Hi Keith:

Even if you managed to get the Session cookie copied over - it
wouldn''t make sense when it arrives at a different server or even on
the same server in a different ASP.NET application. Session is per
application and application A has no knowledge or ability to map
session information in application B.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Mon, 21 Feb 2005 23:30:43 -0600, "Keith Patrick"
<ri*******************@nospam.hotmail.com> wrote:
来自HttpRequest的域名为null(路径为/),但是如果我按原样复制那些
,我会得到一个争论时间。我打电话给
HttpWebRequest.CookieContainer.Add。我现在正在做的是设置域名为
uri.Host,同时设置Cookie.Path = HttpCookie.Path。在超时(WebException,而不是TimeoutException)之后处理响应,并且它具有每个cookie的2个副本,所有这些副本都具有空域和/。路径。
当复制ASP.Net_SessionId cookie时,双重的cookie只会出现问题 - 超时 - 超时。我希望得到某些关于cookie /会话机制的理解比
标准文章(没有阅读IL :)好一点,我可以找出为什么
cookie的副本即将到来,以及为什么复制的会话cookie导致线程挂起直到超时。
The domain from the HttpRequest is null (path is "/"), but if I copy those
over as-is, I get an argumentexception when I call
HttpWebRequest.CookieContainer.Add. What I''m doing now is setting Domain to
uri.Host while setting Cookie.Path = HttpCookie.Path. The response is
processed after a timeout (WebException, not TimeoutException), and it has 2
copies of each cookie, all of them having a null Domain and "/" for path.
The double set of cookies is only being problematic - the timeouts - when
the ASP.Net_SessionId cookie is copied over. I''m hoping to get some kind of
understanding as to the cookie/session mechanism a bit better than the
standard articles (without reading IL :) ) to where I can figure out why the
copies of cookies are coming over, and why the copied session cookie is
leading to the thread hanging until timeout.






这篇关于System.Net.HttpWebRequest与System.Web.HttpRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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