確認呼叫者身分的過程,需考量:
入門篇已提供程式碼範例。
決定已驗證使用者是否具備特定業務操作權限。不當授權恐導致資訊洩露/竄改。纏深度防禦的關鍵策略。
範例:R:Employee OR R:Manager OR I:Bob

public static bool Authorized(string rule)
{
bool authorized = false;
IAuthorizationProvider ruleProvider = AuthorizationFactory.GetAuthorizationProvider();
authorized = ruleProvider.Authorize(Thread.CurrentPrincipal, rule);
return authorized;
}
兩類基本授權策略:
GotDotNet 提供資料庫角色授權外掛:DBRulesAuthorizationProvider.zip,安裝後可透過介面管理規則。
Profile 是系統提供給使用者的彈性資訊容器,可包含:
public static void SaveProfile(BaseForm taskForm)
{
if (_profile == null) _profile = new ProfileInfo();
_profile.FormColor = taskForm.FormColor;
_profile.TextColor = taskForm.TextColor;
IProfileProvider profileProvider = ProfileFactory.GetProfileProvider();
profileProvider.SetProfile(Thread.CurrentPrincipal.Identity, _profile);
}
public static void LoadProfile(BaseForm taskForm)
{
if (_profile == null)
{
IProfileProvider profileProvider = ProfileFactory.GetProfileProvider();
_profile = (ProfileInfo)profileProvider.GetProfile(Thread.CurrentPrincipal.Identity);
}
if (_profile == null) _profile = new ProfileInfo();
taskForm.FormColor = _profile.FormColor;
taskForm.TextColor = _profile.TextColor;
}