Home > Net >  Dynamic loading form access control problem
Dynamic loading form access control problem

Time:05-04

 
//have the following objects:
//1, the business form
Public partial class FrmBranch: BaseDock
{
Private PermissionsController Permissions {get; set; }
Public FrmBranch ()
{
InitializeComponent ();
Permissions=new PermissionsController (this);//access control class

//object according to permissions shielding function
InitAutothorizedUI ();
}
}

//2, permissions class
Public class PermissionsController
{
Private BaseDock BaseDock {get; set; }
Private BaseForm BaseForm {get; set; }

///& lt; Summary>
///function module name
///& lt;/summary>
Public string Itemno {get; set; }

Public PermissionsController BaseDock (FRM)
{
Basedock=FRM;
GetItemno ();
}

Public PermissionsController BaseForm (FRM)
{
Baseform=FRM;
GetItemno ();
}

///& lt; Summary>
///check the function of user privilege level
///& lt;/summary>
///& lt; Param name="itemno" & gt;
Public bool CheckUserFuncAuth ()
{
//have function module permissions
Bool IsAuthorization=false;

//determine query access
If (Basedock!=null)
if (! Basedock. GetLiminf (Portal. Gc. The UserInfo. Logno, Itemno, "aaaa"))
{
IsAuthorization=true;
[MessageDxUtil. ShowWarning (" current account "+ Portal. Gc. The UserInfo. Logno +"] not inquire, please contact the system administrator!" );
}

If (Baseform!=null)
if (! Baseform. GetLiminf (Portal. Gc. The UserInfo. Logno, Itemno, "brow"))
{
IsAuthorization=true;
Throw new ArgumentException (" current account [" + Portal. Gc. The UserInfo. Logno + "] not inquire, please contact the system administrator!" );
}

Return IsAuthorization;
}

///& lt; Summary>
///get the current class module name
///& lt;/summary>
///& lt; Returns>
Private void GetItemno ()
{
If (Basedock!=null)
Itemno=BusinessHelper. GetRemovePrefixString (Basedock. The Name, "Frm");

If (Baseform!=null)
Itemno=BusinessHelper. GetRemovePrefixString (Baseform. The Name, "Frm");
}

}



Because the form is a dynamic instantiation of loading, when CheckUserFuncAuth () method, which is True, termination FrmBranch form of materialization, this how to control implementation, consult a great god,

CodePudding user response:

Termination? Has not terminated,

You want to close my XXX xx=new XXX (); This is the logic, so you can do is throw an exception, so this new exception directly, of course this is logic, anti-patterns operation

Positive logic, positive mode operation is as follows (after I have to netcore Ihost universal host system as an example, because I don't want to tangle in the past 20 years of those things, and your future is bound to contact him, maui, for example)

Since netcore, said after the user login is a sope surial, and your form will also depend on the user context, so he finally designed

The class user context
{Isope sope;
User context (iserviceprovdier provider)
Public void the login ()
{
Sope provider. Newsope ()
}

Public list}


Service. Add
Service. AddSocpeService. AddSocpe (p=& gt; P. user context. The business forms)//according to user context filter business form


Pure hand design, represent the future in general only the host Ihost this mode how to design the system of ideas (not represent you can directly to knock into the vs), we put a little away so as to suit the future not be eliminated (from now on should contact and understand them, don't give out a couple of years by the new people directly) -- -- -- -- -- -- -- -- -- -- -- -- obviously in this general host Ihost mode, you will become more clear own doing, you will easily in the right place to write the correct structure, so he has the universality of the future are more easily accepted by the future of the couple (left), of course, is not willing to accept the old people can only

CodePudding user response:

New PermissionsController (this);
You can naturally in PermissionsController for incoming FrmBranch instance to do any operation, including the destruction
  •  Tags:  
  • C#
  • Related