/// <summary> /// 設定IPrincipal /// </summary> private void SetPrincipal(string userid) { //// 設定使用者識別 => 就是使用者名稱啦 //// GenericIdentity.IsAuthenticated 預設為true GenericIdentity identity = new GenericIdentity(userid); account acc = new account(); String[] mMyStringArray = acc.ListUserRoles(userid).ToArray();//{ "admin" }; //// 將使用者的識別與其所屬群組設定到GenericPrincipal類別上 GenericPrincipal principal = new GenericPrincipal(identity, mMyStringArray); Thread.CurrentPrincipal = principal; if (HttpContext.Current != null) { HttpContext.Current.User = principal; } }