2021-10-10 19:10:40 +08:00
|
|
|
|
//using Yi.Framework.Model;
|
|
|
|
|
|
//using Microsoft.AspNetCore.Authentication;
|
|
|
|
|
|
//using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
//using System;
|
|
|
|
|
|
//using System.Collections.Generic;
|
|
|
|
|
|
//using System.Linq;
|
|
|
|
|
|
//using System.Security.Claims;
|
|
|
|
|
|
//using System.Text;
|
|
|
|
|
|
//using System.Threading.Tasks;
|
2021-10-10 17:30:31 +08:00
|
|
|
|
|
2021-10-10 19:10:40 +08:00
|
|
|
|
//namespace CC.ElectronicCommerce.WebCore
|
|
|
|
|
|
//{
|
|
|
|
|
|
// public static class CommonExtend
|
|
|
|
|
|
// {
|
|
|
|
|
|
// public static bool IsAjaxRequest(this HttpRequest request)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// string header = request.Headers["X-Requested-With"];
|
|
|
|
|
|
// return "XMLHttpRequest".Equals(header);
|
|
|
|
|
|
// }
|
2021-10-10 17:30:31 +08:00
|
|
|
|
|
2021-10-10 19:10:40 +08:00
|
|
|
|
// /// <summary>
|
|
|
|
|
|
// /// 基于HttpContext,当前鉴权方式解析,获取用户信息
|
|
|
|
|
|
// /// </summary>
|
|
|
|
|
|
// /// <param name="httpContext"></param>
|
|
|
|
|
|
// /// <returns></returns>
|
|
|
|
|
|
// public static UserInfo GetCurrentUserInfo(this HttpContext httpContext)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// IEnumerable<Claim> claimlist = httpContext.AuthenticateAsync().Result.Principal.Claims;
|
|
|
|
|
|
// return new UserInfo()
|
|
|
|
|
|
// {
|
|
|
|
|
|
// id = long.Parse(claimlist.FirstOrDefault(u => u.Type == "id").Value),
|
|
|
|
|
|
// username = claimlist.FirstOrDefault(u => u.Type == "username").Value ?? "匿名"
|
|
|
|
|
|
// };
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|