Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi there.
I'm having a trouble with the authorization system of my application.
I persist the users, roles and permission per role on a MySQL database.
I'm trying to assign permission by object type:
- Menu option (Cool Vista-style menu by Nedim Sabic, great control by the way)
- Forms (I developed a basic form and inherit from that all the other forms)
- Buttons (all the buttons are inherited from a basic class too).

At my base form class, at the LOAD event, I'm checking the authorization for the specific user (based on his/her role):

if (!Autorizaciones.Autorizado(this.Name, _Padre)) // Checks permissions
{
   Autorizaciones.Error(); //Display a message
   Close(); // Close the form
}


But (always a but), even if this works correctly, the form is shown for a few milliseconds.

Is it possible to prevent the creation of the form (or any other object) using another event?

Thanks in advance.

VS2008
MySQL 5.5.10
.NET FrameWork 3.5
Posted
Comments
pankajupadhyay29 6-Apr-11 13:31pm    
You can not stop the creation of form but you can check the authorization before calling frm.show() method.

1 solution

0) Do the permission check before even instantiating the form

1) Or you can set the form to be initially hidden (Form.Visible=false;), and only make it visible after the user has been validated.

2) Or you can setup a class that performs the validation and generates an event that your parent form can respond to (and thus instantiate the form AFTER the user has been validated).
 
Share this answer
 
v3
Comments
FernandoUY 6-Apr-11 13:28pm    
Hi John. Thank for your fast reply.

0) Won't work (in my solution), because I need the form created: I use the name of the control to validate.

1) Love it! Really simple
2) BOUGHT IT! This is the best solution! Super-professional!
Tanks John!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900