コード例 #1
0
        // Gets the username for the requesting authorized claim/token
        internal string GetUsernameForRequest()
        {
            try
            {
                var userClaim = User.FindFirstValue(ClaimTypes.NameIdentifier);

                if (!String.IsNullOrEmpty(userClaim))
                {
                    // Make sure we have a valid id that can be parsed to an int
                    if (Int32.TryParse(userClaim, out int id))
                    {
                        return(AppSecurity.GetClaimUsernameById(id));
                    }
                }
            }
            catch (Exception ex)
            {
                AppLogger.LogError(nameof(GetUsernameForRequest), ex.Message);
            }

            // Something happened so just return empty string
            return(String.Empty);
        }