我正在尝试创建WebRequest
的实例,但它会抛出异常。
代码:
WebRequest request = WebRequest.Create("somURL");
错误:
System.NullReferenceException: Object reference not set to an instance of an object.
此代码正在处理本地环境,但在客户端生产服务器上失败。
注意:客户最近更改了托管。 .Net Framework是3.5。
完全例外:
System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessPermission.Demand() at System.Net.HttpWebRequest..ctor(Uri uri, ServicePoint servicePoint) at System.Net.HttpRequestCreator.Create(Uri Uri) at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase) at System.Net.WebRequest.Create(String requestUriString) at
答案 0 :(得分:0)
查看异常,看起来Code Access Security已经提出了这个问题。我看到一个类似的帖子,请看一下。