如何申请类型System.Net.WebPermission在ASP.NET MVC权限?(How

2019-07-21 01:28发布

我创建,创建一个小的网络服务HttpWebRequest使用代理到另一个网站,我使用代理服务器后,我得到了错误:

请求类型“System.Net.WebPermission,系统,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089”的许可失败。

我不知道如何解决它的想法。

这里是我的代码,

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://website.com");
req.CookieContainer = c;

req.Proxy = new WebProxy("IP:PORT");

req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB7.4; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)";
req.Accept = "application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
req.Headers.Add("Accept-Language", "en-US");
req.ServicePoint.Expect100Continue = false;
req.AllowAutoRedirect = false;
req.Timeout = 10000;
req.Method = "GET";
req.KeepAlive = true;
req.ProtocolVersion = HttpVersion.Version10;

Answer 1:

It seems that you are running into a trust related issue. You might be able to work-around the issue by including in your Web.Config, under System.Web,

<trust level="Full" />

WebPermission is not available under a medium trust environment (and you can look at this article to modify this behavior and for the reasons why you shouldn't).

However, if you require full trust you might have to reconsider the requirements of your application.



Answer 2:

去你的项目/应用程序的性能(WPF)

在安全选择启用clickone securitysetting。 该项目的设置信任级别



Answer 3:

我也有这个问题 - 它竟然是由于对DLL执行具有从网上下载的Web请求。

我不得不进入在文件浏览器的DLL的属性(右键点击>属性),然后点击“解除阻止” - 确保单击“应用”,然后“确定”。



文章来源: How to request a permission of type System.Net.WebPermission in ASP.NET MVC?