如何申请类型System.Net.WebPermission在ASP.NET MVC权限? [英] How to request a permission of type System.Net.WebPermission in ASP.NET MVC?
问题描述
我创建,创建一个的HttpWebRequest
至其他网站使用代理一个小型Web服务
我用代理服务器后,我得到这个错误:
申请类型的权限'System.Net.WebPermission,系统,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089'失败。
块引用>我不知道如何解决它的主意。
下面是我的code,
HttpWebRequest的REQ =(HttpWebRequest的)WebRequest.Create(http://website.com);
req.CookieContainer = C;req.Proxy =新WebProxy(IP:端口);req.UserAgent =Mozilla的/ 4.0(兼容; MSIE 8.0; Windows NT的6.1; WOW64;三叉戟/ 4.0; GTB7.4; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729 ;媒体中心PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2);
req.Accept =应用程序/ x-MS-应用,图像/ JPEG,应用/ XAML的+ XML,图像/ GIF,图像/ PJPEG,应用程序/ x-MS-XBAP,应用程序/ vnd.ms - Excel中,应用程序/越南盾.MS-PowerPoint中,应用程序/ msword,* / *;
req.Headers.Add(接受语言,EN-US);
req.ServicePoint.Expect100Continue = FALSE;
req.AllowAutoRedirect = FALSE;
req.Timeout = 10000;
req.Method =GET;
req.KeepAlive = TRUE;
req.ProtocolVersion = HttpVersion.Version10;
解决方案看来你正在运行到一个的信任的相关问题。你也许可以通过在你的
web.config中工作,解决这个问题
,在的System.Web
,<信任级别=完全/>
WebPermission的
是下了中等信任
环境不可用(你可以看看<一个href=\"http://blogs.iis.net/hosterposter/archive/2006/03/22/Enabling-WebPermission-in-Medium-Trust.aspx\"相对=nofollow>这篇文章修改此行为,究其原因,为什么你不应该)。然而,如果你需要
完全信任
你可能要重新考虑你的应用程序的要求。I created a small web service that creates a
HttpWebRequest
to another website using a proxy and after i used the proxies i got that error:Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
I have no idea about how to fix it.
Here is my code,
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;
解决方案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
, underSystem.Web
,<trust level="Full" />
WebPermission
is not available under amedium 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.这篇关于如何申请类型System.Net.WebPermission在ASP.NET MVC权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!