/// <summary> /// /// </summary> /// <returns></returns> /// <exception cref="UnauthorizedAccessException"></exception> public static User GetUser() { WindowsIdentity identity = (WindowsIdentity)HttpContext.Current.Request.RequestContext.HttpContext.User.Identity; if( identity == null || identity.User == null ) { throw new UnauthorizedAccessException(); } string sid = identity.User.AccountDomainSid.Value; if( Users.ContainsSID( sid ) ) { return Users[ sid ]; } string[] a = identity.Name.Split( '\\' ); DirectoryEntry entry = new DirectoryEntry( "WinNT://" + a[ 0 ] + "/" + a[ 1 ] ); string name = entry.Properties[ "FullName" ].Value.ToString(); using( DBCommand cmd = new DBCommand( Con, CommandType.StoredProcedure ) ) { cmd.CommandText = "GetUser"; SqlParameter id = cmd.Add( "@User_ID", SqlDbType.Int, ParameterDirection.InputOutput, DBNull.Value ); cmd.AddWithValue( "@SID", sid ); cmd.AddWithValue( "@Name", name ); User user = null; while( cmd.Read() ) { if( user == null ) { user = new User { ID = cmd.GetInt( "User_ID" ), Name = cmd.GetString( "Name" ), SID = sid }; } if( !cmd.IsDBNull( "Team_ID" ) ) { user.Teams.AddDistinct( Teams.GetByID( cmd.GetInt( "Team_ID" ) ) ); } } Users.AddDistinct( user ); } return Users[ sid ]; }