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

发布于 2024-09-29 12:50:50 字数 956 浏览 1 评论 0原文

我已经下载了1.0.1.0和1.0.4.0中的recaptcha.dll。 当尝试渲染控件时,出现以下异常:

安全异常 描述:应用程序试图执行安全策略不允许的操作。要授予此应用程序所需的权限,请联系您的系统管理员或在配置文件中更改应用程序的信任级别。

异常详细信息:System.Security.SecurityException:请求“System.Web.AspNetHostingPermission,System,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”类型的权限失败。

堆栈跟踪:[SecurityException:请求“System.Web.AspNetHostingPermission,System,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”类型的权限失败。] System.Reflection.Assembly._GetType(字符串名称,布尔值 throwOnError,布尔值ignoreCase)+0 System.Web.UI.NamespaceTagNameToTypeMapper.GetControlType(String tagName, IDictionary attribs, Boolean throwOnError) +209

快速谷歌搜索提供的解决方案是使用 caspol.exe 添加对 recaptcha.dll 程序集的完全信任。

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

此时,出现以下错误:

错误:此程序集未签名强名称

除了下载源代码并在本地重新编译之外,还有其他方法可以使其正常工作吗?

I've downloaded the recaptcha.dll in both 1.0.1.0 and 1.0.4.0.
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.

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

The solution to this, as provided by a quick Googling, is to use caspol.exe to add full trust to the recaptcha.dll assembly.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

抱着落日 2024-10-06 12:50:50

我遇到了同样的问题,你的解决方案帮助了我。我还必须对 reCAPTCHA ASP.NET 源代码执行以下步骤。

1) 打开DLL项目的AssemblyInfo.cs文件并添加以下using语句。

使用系统安全;

2) 将以下行添加到 AssembleInfo.cs。

[程序集:AllowPartiallyTrustedCallers()]

3) 重新编译 dll 并重新部署您的项目。这个错误应该得到解决。

注意:我正在开发的网站使用 1and1.com 作为其托管公司。我还必须在代码隐藏中设置 Proxy 属性,以避免 HttpWebRequest 期间出现超时异常。

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

希望这对某人有帮助,但现在我已经在 1and1.com 托管的 ASP.NET 网站上启动并运行了 reCAPTCHA。

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.

1) Open the AssemblyInfo.cs file of the DLL project and add following using statement.

using System.Security;

2) Add following line to AssembleInfo.cs.

[assembly: AllowPartiallyTrustedCallers()]

3) Recomiple the dlls and redeploy your projects. This error should be solved.

NOTE: The website I am working on is using 1and1.com as their hosting company. I also had to set the Proxy property in the code-behind to avoid a timeout exception during the 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.

丶情人眼里出诗心の 2024-10-06 12:50:50

我也有同样的问题。经过一番思考后,我意识到我已经从 zip 文件中下载了 recaptcha.dll。因此,我右键单击该 dll,转到属性并单击取消阻止按钮。

这为我解决了这个问题。

I had this same issue. After some headbanging, I realized that I had downloaded the recaptcha.dll from a zip file. So, I right-clicked on the dll, went to properties and clicked the unblock button.

That solved the issue for me.

烟若柳尘 2024-10-06 12:50:50

我在尝试将 Google 的 reCAPTCHA 部署到 hostmysite.com 上共享托管环境中的生产服务器时遇到了两个不同的安全问题

1) 首先,我根本无法显示表单。相反,我会看到一条错误消息,指出“该程序集不允许部分受信任的调用者”。通过下载某人从源代码重新编译并添加 [程序集:AllowPartiallyTrustedCallers] 的 DLL 可以解决此问题。 DLL 下载和更多详细信息在这里:
https://code.google.com/p/recaptcha/issues/detail ?id=100

2) 部署该 DLL 后,我能够让 reCAPTCHA 最初显示在表单上,​​但提交表单会导致原始帖子中列出的相同安全错误:

“描述:应用程序尝试执行安全策略不允许的操作。要授予此应用程序所需的权限,请联系您的系统管理员或更改配置文件中的应用程序的信任级别”

我向我们的托管支持提交了票证,他们能够修复该问题。问题,解释如下:

“它可能在您的计算机上运行,​​因为您将其设置为完全信任环境,而该站点所在的 Web 服务器设置为中等信任。因此,它具有一组受信任的 URI 的限制。我现在已将 Google 的 Recaptcha 的 URI 添加到受信任列表中,并且您的表单现在可以在该网站上使用。如果您还有任何其他问题,请告诉我们。”

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

1) First, I couldn't get the form to display at all. 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]. The DLL download and more details are here:
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:

"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."

许仙没带伞 2024-10-06 12:50:50

由于无法使用可供下载的未签名 dll 来使其工作,我找到了源代码,自己编译并签名了它,效果很好。

如果一路上有什么事情表明我可能不得不这样做,那就太好了……

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.

It would have been great if something, somewhere along the way, had indicated that I might have to do this...

故人爱我别走 2024-10-06 12:50:50

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

In the IIS go to the Application Pool, there got to your project, right click and select Advanced Properties and set LoadUserProfile to True.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文