Restricting user rights by hiding controls - enough?

Last post 01-08-2007 10:23 PM by agolden. 2 replies.

Sort Posts:

  • Restricting user rights by hiding controls - enough?

    01-08-2007, 9:51 PM
    • Member
      48 point Member
    • HiTech2k
    • Member since 09-16-2006, 4:34 AM
    • Posts 20

    Dear forums,

    I would like to restrict user rights by hiding controls on the page based on membership. "Theoretically", this would make it impossible for those controls to raise events on the server side. However, I wonder if a malicious user could raise those events by instantiating the controls on the client side anyway (e.g. XSS).

    Sample scenario: There is a button on the page that is enabled / visible only if user is member of a certain role (rights checked on Page Load event).
    Can disabling/hiding the button be bypassed by some tricky way of postback that would invoke the associated click event anyway?

    Thanks for advice.

  • Re: Restricting user rights by hiding controls - enough?

    01-08-2007, 10:05 PM
    Answer
    • Contributor
      3,964 point Contributor
    • Nullable
    • Member since 05-02-2006, 8:01 PM
    • Posts 740

    You're safe... as long as you hide those controls OnInit... they will not fire events.

    Please mark this post as the "answer" if it meets your needs :)

    -Timothy Khouri
    http://www.SingingEels.com/
    Developer / Architect / Author
  • Re: Restricting user rights by hiding controls - enough?

    01-08-2007, 10:23 PM
    Answer
    • Star
      7,685 point Star
    • agolden
    • Member since 08-03-2002, 6:56 AM
    • Houston, TX
    • Posts 1,036

    In ASP.NET 2, when a control is rendered, all of its valid events get registered.  If an event is raised that was not registered, an exception is thrown (assuming the Page EnableEventValidation is no set to false).  So, if a button is not visible, it's events can't be raised.

    Hope that helps.

    Aaron

    Don't forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so everyone will know you have been helped.
Page 1 of 1 (3 items)