I'm getting a security Exception in a Winforms User Control embedded within a web page using the <OBJECT> tag.
It reads as:-
Request for the permission of type System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
This is not a beginners problem....
I'm fully aware of Code Access security and have alot of experience working with it and winforms.net controls embedded inside the web browser.
The cause of this exception seems to be the following line of code...
public static string GetStandardPrefix(Control aControl)
NumericTextBox numericTextBoxControl = aControl as NumericTextBox;
I can eliminate the exception (at the loss of functionality) by removing this line of code so I'm absolutely certain the problem lies here.
NumericTextBox is a control I've created subclassed from the winforms TextBox control.
I have subclassed several controls, I get the same exception when if attempt to cast those.... I don't get this exception if I try to do...
System.Windows.Forms.TextBox textBoxControl = aControl as System.Windows.Forms.TextBox;
My code works fine when run within a standard winforms exe application.
I can't see a work around other than only using standard windows controls....
Can anyone out there help me out here ?
Fusion Technology Group Pty Ltd
Ph 61 (0) 417 498 620
My application doesn't make any access to system resources such as the registry or the hard disk (except through Isolated Storage). The web site falls into the Local Intranet zone of the client machines I have tested with. Everying the app does visually is pretty normal.
The NumericTextBox control doesn't override any of the standard TextBox's members, all it does is supply additional members... a Value property and a ValueChanged event.
At the point where the exception is occuring all that is happening is we are casting to the type it's not necessarily even been instanced yet. In fact at the point where I'm getting the exception I can say with absolute certainty no instance of the NumericTextBox control has been created. The exception results simply from attempting to cast to the NumericTextBox type using the keyword 'as' all I expected it to do was return null, instead it's throwing an exception.
I was just asking about the VisualizationPermission because basically, if it's not in mscorlib, you won't be able to do it by default. Say you want to have the FormBorderStyle Property set to None, you'll get a security exception unless you have Visual Permissions for that application.
Not sure how to fix your problem! :~
Since this is an intranet, have you tried going in and giving all local intranet apps full trust or medium trust? Would that be an option for you?
What is a VisualizationPermission ?
I can't see anything in the docs, nor does google return me anything.
I have adjusted the trust level for the intranet (using the "Adjust .NET Security" wizard) to full trust and I'm still getting the exception. So this doesn't seem to be a solution and if it were I'd prefer to have a zero-touch deployable application anyhow.
I've managed to fudge my code to avoid casting to any subclassed windows form controls, so I have a work around, it's not optimal but it'll get me by. It'd be useful though to resolve this issue.
Thanks for your help...
you gave it full trust and it still didn't work? that shouldn't be the case, because when you run it locally then it would run under the same policy, i believe, which is full trust
Sorry about VisualizationPermissions, I guess I made that up, it's actually UIPermission...here's the Remarks from the SDK Help
Drawing and user input events in windows are user interfaces.
The permission to use windows can be one of the following: unrestricted, limited to safe top-level windows, only safe subwindows, or no window drawing or user input event access allowed. Safe windows are restricted in title and size to prevent possible spoofing by potentially harmful code.
The permission to use the clipboard can be one of the following: unrestricted, write-only, or no clipboard access allowed. The paste limitation prevents potentially harmful applications from taking data from the clipboard without the user's consent, while still allowing the Cut, Copy, and Paste operations when initiated by the user through keyboard commands.
If you have VS.NET, just open it up and type this in the address bar: ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemsecuritypermissionsuipermissionclasstopic.htm
I get the same error when trying to 'trickle' load a form (.dll) from a 'no-touch' deployed .exe.
If I have to change the permissions on each client machine (those that are to run the app) then doesn't that mean that 'no-touch' is no true - and should really be 'some-touch'?
Please let me know if there is another work around - I'm very new to all this. I've also tried using and AssemblyKeyFile in the assembly file - with no luck.