Question : SecurityException: Request for the permission of type 'System.Web.AspNetHostingP<wbr />ermission.<wbr />.. Failed

Yesterday I started working on a Web Form that I had started a few weeks ago.

I needed to use an UpdatePanel so I reinstalled the most recent AJAX Control Toolkit.  An older version was installed so I removed it from the Visual Studio 2008 Toolbox and added it to the Toolbox again from the new .dll.

Now I'm getting a Security Exception error.  (See Code snippet window.)

The Web Form loads up just fine and the VB code to hide items depending on the selction of radiobuttons works and all, but when I Submit the form I do not get any errors, but the data is not sent to the database and the form stops functioning (hide the field toggles mentioned above for example)

With a CalendarExtendar on a TextBox on the form I get an error like this:
Error      8      Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.      \\intraserve\e$\Inetpub\PPN\Default.aspx      104      

I also received this error:
Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC LM 8)
Timestamp: Thu, 19 Nov 2009 13:14:51 UTC


Message: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'System.Data.SqlClien'.
Line: 4723
Char: 21
Code: 0
URI: http://ppn.wf1broward.com/ScriptResource.axd?d=XdbemCab4u0xAKP8_L-8bbfkp5ij31LYjZ4-BZGvnNvz3rOykjcofk8-V-5qDYRiIe9Z4RbrNcCqR_nvqc8J3aWe85WfaMCu9JiR73Sr3TI1&t=ffffffffefb44ae8

From what I've been able to find it sounds like a Full Trust issue, but I'm not sure.

I created a new Project from scratch and a new Default.aspx form.
I dragged a ScriptManager on the form between the two
tags and typed "test" below the ScriptManager.  I Debugged it and that's when I actually got the error in the Code snippet below.  The page has nothing but the ScriptManager and the word "test".

I tested another existing web form that has been in production for many months and it still works fine, data updates and all.

What could I have broken?

Oh, I'm developing the web form on the server through a UNC path.  My project location looks like this:  \\WebServer\e$\Inetpub\PPN\
But that's the way I've always done my projects.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
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.
 
Source Error: 
 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
 
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.Reflection.Assembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase) +42
   System.Web.UI.Util.GetTypeFromAssemblies(ICollection assemblies, String typeName, Boolean ignoreCase) +145
   System.Web.UI.TemplateParser.GetType(String typeName, Boolean ignoreCase, Boolean throwOnError) +73
   System.Web.UI.TemplateParser.ProcessInheritsAttribute(String baseTypeName, String codeFileBaseTypeName, String src, Assembly assembly) +111
   System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary parseData) +279
 
 
 
 
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082

Answer : SecurityException: Request for the permission of type 'System.Web.AspNetHostingP<wbr />ermission.<wbr />.. Failed

1) I would write the message, not the Exception:

Response.Write(exp.Message)

2) You are returning a value from the INSERT statement, but ignoring the return with ExecuteScalar.  That looks more like an implied ExecuteNonQuery.

3) Simplified code:

            DBCmd.Parameters.AddWithValue("@txtPPNWorkshopLocation", txtPPNWorkshopLocation.Text)
            DBCmd.Parameters.AddWithValue("@txtPPNCode", txtPPNCode.Text)
            DBCmd.Parameters.AddWithValue("@txtLastName", txtLastName.Text)
            DBCmd.Parameters.AddWithValue("@txtFirstName", txtFirstName.Text)
 
4) I still can't see why nothing is written, if you are not getting any exceptions.
Random Solutions  
 
programming4us programming4us