Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Unsafe code in user control

Unsafe code in user control

Scheduled Pinned Locked Moved C#
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shree
    wrote on last edited by
    #1

    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?

    D 1 Reply Last reply
    0
    • S Shree

      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?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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

        S Offline
        S Offline
        Shree
        wrote on last edited by
        #3

        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.

        D 1 Reply Last reply
        0
        • S Shree

          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.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups