Unsafe code in user control
-
Is it not allowed to have unsafe code in an user control that I want to host on a browser? The user control is working properly, and when I compile with the unsafe flag, it stops appearing on the web page. Is there some workaround?
It depends on the code. There is some stuff that you just cannot do in a browser because it's a security violation. You can't, for instance, P/Invoke code in a .DLL from a browser hosted instance of a control. Manipulating the File System of a client is also a no-no. Let's see a code snippet of what your trying to do and maybe there will be a workaround. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
It depends on the code. There is some stuff that you just cannot do in a browser because it's a security violation. You can't, for instance, P/Invoke code in a .DLL from a browser hosted instance of a control. Manipulating the File System of a client is also a no-no. Let's see a code snippet of what your trying to do and maybe there will be a workaround. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
No, it is just turning on the Allow Unsafe Code blocks in the Project Settings page. My user control has an Image control, and have raw image bits. I am trying to use BitmapData to render the image bits fast. I think this should not pose a security violation.
-
No, it is just turning on the Allow Unsafe Code blocks in the Project Settings page. My user control has an Image control, and have raw image bits. I am trying to use BitmapData to render the image bits fast. I think this should not pose a security violation.
The 'unsafe' switch tags you entire assembly as unsafe code. This means, in IE, that your code isn't safe and won't be executed, depending on the security setting your running in IE and the Code Access Security policies you have setup. You'll have to check with the .NET Framework Configuration tool or the Code Access Security Policy tool and make sure that you can run unsafe code from a remote location. By default, you can't run untrusted code from a remote location, like a component loaded from a server. You can also start by reading Securing Applications[^] for an explanation about how Code Access Security works and why you can't run Unsafe code in IE and how to make it work. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome