首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

WebClient 在winxp win2003下的奇怪有关问题

2013-09-28 
WebClient 在winxp win2003下的奇怪问题这是怎么回事?[解决办法]The problem is redirection by the websU

WebClient 在winxp win2003下的奇怪问题



这是怎么回事?
[解决办法]
The problem is redirection by the webs

Unfortunately you have to subclass WebClient to fix this. This is harder than it looks because Silverlight (any flavour) doesn't like this and throws an inheritance related exception until you guess that you need to override the ctor and attribute it as SecurityCritical.


public class WebClient2 : WebClient
{
  [SecurityCritical]
  public WebClient2() : base() { }  
  protected override WebRequest GetWebRequest(System.Uri address)
  {
    var wr = base.GetWebRequest(address);
    if (wr is HttpWebRequest)
      (wr as HttpWebRequest).AllowAutoRedirect = false;
    return wr;
  }
}


If you want to go further you could surface an AllowAutoRedirect property on WebClient2 and hook it all up.

代码和解释来自stackoverflow
Why does this exception claim the code doesn't write data?
http://stackoverflow.com/questions/6636009/why-does-this-exception-claim-the-code-doesnt-write-data

热点排行