using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; namespace Bootstrap.Admin.Controllers.Api { /// /// 在线用户接口 /// [Route("api/[controller]")] [ApiController] public class OnlineUsersController : ControllerBase { /// /// 获取所有在线用户数据 /// /// [HttpPost()] public IEnumerable Post([FromServices]IOnlineUsers onlineUSers) { return onlineUSers.OnlineUsers.OrderByDescending(u => u.LastAccessTime); } /// /// 获取指定会话的在线用户请求地址明细数据 /// /// /// /// [HttpGet("{id}")] public IEnumerable> Get(string id, [FromServices]IOnlineUsers onlineUSers) { var user = onlineUSers.OnlineUsers.FirstOrDefault(u => u.ConnectionId == id); return user?.RequestUrls ?? new KeyValuePair[0]; } } }