I want to implement user security. Am I correct in understanding that I should use the CheckSecurity method on the business object to determine that an action is to be allowed or denied THEN use the SecurityDenied method in the object on the form to display the denied message to the user?
Yes, you are correct there.
Within the SecurityDenied event handler, the event arguments tell you what action was denied. Beyond that, you will need to store off any additional information necessary to provide a complete message to the end user. Your best bet for storing off information (including storing off a "global" business object) is to create a sealed class within your application's root namespace called "Globals" or some other name that makes sense to you. Then you can place a static (shared) member/property combination to store the global users business object and another member/property pair to store off any other information necessary.
namespace RootNamespace
{
public sealed class Globals
{
#region Private Fields
private static UsersBO _CurrentUser = new UsersBO();
private static string _ErrorMessage = "";
#endregion
#region Public Properties
public static UsersBO CurrentUser
{
get
{
return Globals._CurrentUser;
}
set
{
Globals._CurrentUser = value;
}
}
public static string ErrorMessage
{
get
{
return Globals._ErrorMessage;
}
set
{
Globals._ErrorMessage = value;
}
}
#endregion
}
}
You could then access these properties from anywhere by accessing RootNamespace.Globals.CurrentUser or RootNamespace.Globals.ErrorMessage.
Hope that makes sense