⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 st_principal.cs

📁 数据库:Microsoft SQL Server 2000。 技术平台:Microsoft .NET Framework 2.0.0.0版本。 IIS:Internet Informati
💻 CS
字号:
using System;
using System.Security.Principal;
using System.Collections;
using System.Globalization;
using Microsoft.ApplicationBlocks.Data;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace STGROUP.ST_ExamBiz
{
	/// <summary>
	/// ST_Principal 的摘要说明。
	/// </summary>
	public class ST_Principal: IPrincipal
	{
		private ST_Identity _identity;
		private string[] _roles;
		private readonly string connectionString;
		public ST_Principal(ST_Identity identity, string[] roles)
		{
			connectionString = (string)ConfigurationSettings.AppSettings["ConnString"];
			if(identity == null)
			{
				throw new ArgumentNullException("identity");
			}
			_identity = identity;

			if(roles != null)
			{
				_roles = new string[roles.Length];
				for(int i = 0; i < roles.Length; i++)
				{
					_roles[i] = roles[i];
				}
				return;
			}
			_roles = null;
		}
		public string[] Roles
		{
			get
			{
				return _roles;
			}
		}
		#region IPrincipal 成员
		
		/// <summary>
		/// 只读属性,返回TopGeneIdentity
		/// </summary>
		public IIdentity Identity
		{
			get
			{
				return _identity;
			}
		}

		/// <summary>
		/// IPrincipal.IsInRole的实现
		/// </summary>
		/// <param name="role">要验证的角色名</param>
		/// <returns></returns>
		public bool IsInRole(string role)
		{
			int num1;
			if(role == string.Empty || role == null)
				throw new ArgumentNullException("role");
			if (_roles == null)
			{
				return false;
			}
			for (num1 = 0; (num1 < _roles.Length); num1 += 1)
			{
				if(_roles[num1] == "Administrators")
					return true;
				if ((_roles[num1] != null) && (string.Compare(_roles[num1], role, true, CultureInfo.InvariantCulture) == 0))
				{
					return true;
				}
			}
			return false;
		}

		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -