Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 236
Andrew Arnott Avatar asked Oct 29 '10 08:10

Andrew Arnott


2 Answers

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.

like image 102
Andrew Brown Avatar answered Sep 23 '22 14:09

Andrew Brown


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.

like image 41
Brad Falk Avatar answered Sep 25 '22 14:09

Brad Falk