简体   繁体   English

尝试呈现reCaptcha控件时出现.Net安全异常

[英].Net Security Exception when trying to render a reCaptcha control

I've downloaded the recaptcha.dll in both 1.0.1.0 and 1.0.4.0. 我已经在1.0.1.0和1.0.4.0中下载了recaptcha.dll。 When trying to render the control, I get the following exception: 尝试呈现控件时,出现以下异常:

Security Exception Description: The application attempted to perform an operation not allowed by the security policy. 安全异常描述:应用程序尝试执行安全策略不允许的操作。 To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 要授予此应用程序所需的权限,请联系系统管理员或在配置文件中更改应用程序的信任级别。

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. 异常详细信息:System.Security.SecurityException:请求类型为“ System.Web.AspNetHostingPermission,系统,版本= 2.0.0.0,区域性=中性,PublicKeyToken = b77a5c561934e089”的权限失败。

Stack Trace:[SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.] System.Reflection.Assembly._GetType(String name, Boolean throwOnError, Boolean ignoreCase) +0 System.Web.UI.NamespaceTagNameToTypeMapper.GetControlType(String tagName, IDictionary attribs, Boolean throwOnError) +209 堆栈跟踪:[SecurityException:请求类型为'System.Web.AspNetHostingPermission,系统,版本= 2.0.0.0,区域性=中性,PublicKeyToken = b77a5c561934e089'的权限。] System.Reflection.Assembly._GetType(字符串名称,布尔值throwOnError,布尔值ignoreCase)+0 System.Web.UI.NamespaceTagNameToTypeMapper.GetControlType(String tagName,IDictionary attribs,布尔throwOnError)+209

The solution to this, as provided by a quick Googling, is to use caspol.exe to add full trust to the recaptcha.dll assembly. 快速谷歌搜索提供的解决方案是使用caspol.exe将完全信任添加到recaptcha.dll程序集。

C:\\%path%\\caspol -af C:\\inetpub\\wwwroot\\%path%\\bin\\recaptcha.dll C:\\%path%\\ caspol -af C:\\ inetpub \\ wwwroot \\%path%\\ bin \\ recaptcha.dll

At this point, I get the following error: 在这一点上,我得到以下错误:

ERROR: This assembly is not strong name signed 错误:此程序集不是用强名称签名的

Short of downloading the source code and recompiling it locally, is there any other way to get this working? 除了下载源代码并在本地重新编译之外,还有其他方法可以使它工作吗?

I ran into the same problem and your solution helped me. 我遇到了同样的问题,您的解决方案帮助了我。 I also had to perform the following steps on the reCAPTCHA ASP.NET source code. 我还必须对reCAPTCHA ASP.NET源代码执行以下步骤。

1) Open the AssemblyInfo.cs file of the DLL project and add following using statement. 1)打开DLL项目的AssemblyInfo.cs文件,并添加以下using语句。

using System.Security; 使用System.Security;

2) Add following line to AssembleInfo.cs. 2)将以下行添加到AssembleInfo.cs。

[assembly: AllowPartiallyTrustedCallers()] [程序集:AllowPartiallyTrustedCallers()]

3) Recomiple the dlls and redeploy your projects. 3)重新组合dll并重新部署您的项目。 This error should be solved. 该错误应得到解决。

NOTE: The website I am working on is using 1and1.com as their hosting company. 注意:我正在使用的网站正在使用1and1.com作为其托管公司。 I also had to set the Proxy property in the code-behind to avoid a timeout exception during the HttpWebRequest. 我还必须在后面的代码中设置Proxy属性,以避免HttpWebRequest期间发生超时异常。

recaptcha.Proxy = new WebProxy("http://ntproxyus.lxa.perfora.net:3128");

Hope this helps someone but now I have reCAPTCHA up and running on an ASP.NET site hosted on 1and1.com. 希望这对某人有帮助,但是现在我已经在1and1.com上托管的ASP.NET网站上运行reCAPTCHA。

I had this same issue. 我有同样的问题。 After some headbanging, I realized that I had downloaded the recaptcha.dll from a zip file. 经过一番猛烈抨击,我意识到我已经从一个zip文件下载了recaptcha.dll。 So, I right-clicked on the dll, went to properties and clicked the unblock button. 因此,我右键单击dll,转到属性,然后单击取消阻止按钮。

That solved the issue for me. 那为我解决了这个问题。

I ran into two different security issues while trying to deploy Google's reCAPTCHA to our production server in a shared hosting environment on hostmysite.com 在尝试在hostmysite.com上的共享托管环境中将Google的reCAPTCHA部署到生产服务器时,我遇到了两个不同的安全问题。

1) First, I couldn't get the form to display at all. 1)首先,我根本无法显示该表单。 Instead, I would see an error message that said "That assembly does not allow partially trusted callers." 相反,我会看到一条错误消息,内容为“该程序集不允许部分受信任的调用方。” That was fixed by downloading a DLL that someone recompiled from source code with the addition of [assembly: AllowPartiallyTrustedCallers]. 通过下载有人从源代码重新编译的DLL并添加[assembly:AllowPartiallyTrustedCallers]可以解决此问题。 The DLL download and more details are here: https://code.google.com/p/recaptcha/issues/detail?id=100 DLL下载和更多详细信息,请参见: https : //code.google.com/p/recaptcha/issues/detail?id=100

2) After deploying that DLL I was able to get the reCAPTCHA to initially display on the form, but submitting the form resulted in the same security error listed in the original post: 2)部署该DLL之后,我能够使reCAPTCHA最初显示在表单上,​​但是提交表单会导致原始帖子中列出的相同安全错误:

"Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. " “描述:应用程序尝试执行安全策略不允许的操作。要授予此应用程序所需的权限,请与系统管理员联系或在配置文件中更改应用程序的信任级别。”

I submitted a ticket to our hosting support and they were able to fix that problem, with this explanation: 我向我们的托管支持人员提交了一张票,他们能够解决此问题,并带有以下解释:

"It was probably working on your computer because you have it set to a Full Trust environment whereas the web server that the site is on is set to Medium Trust. It therefore has a restricted set of trusted URIs. I have now added the URI for Google's Recaptcha to the trusted list and your form is now working on the site. If you have any further issues, do let us know." “它可能在您的计算机上工作,因为您将其设置为完全信任环境,而站点所在的Web服务器设置为中等信任。因此,它具有受限制的受信任URI集。我现在为Google的Recaptcha到受信任列表,您的表格现在可以在该网站上使用。如果还有其他问题,请告诉我们。”

Being unable to get this to work using the unsigned dll that is made available for download, I got hold of the source, compiled and signed it myself and this works fine. 无法使用可供下载的未签名dll来使它正常工作,我掌握了源代码,并自行对其进行了编译和签名,因此效果很好。

It would have been great if something, somewhere along the way, had indicated that I might have to do this... 如果在途中某处有迹象表明我可能必须这样做,那将是很棒的。

在IIS中,转到“ 应用程序池” ,进入您的项目,右键单击并选择“ 高级属性”,然后将LoadUserProfile设置为True。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM