public async Task <string> LogOffUser(LogOffUserQuery logOffUserQuery) { _logger.LogInformation($"Make api call to log off user session of session id {logOffUserQuery.sessionId}"); string token = Request.Headers["Authorization"]; return(await _userSessionService.LogOffUserSession(token, logOffUserQuery).ConfigureAwait(false)); }
public async Task <IActionResult> LogOffUserSession(DiagnoseDetailPageViewModel data) { var viewData = new LogOffUserQuery(); tenantGroupName = HttpContext.Session.Get <string>("SelectedTenantGroupName"); tenant = HttpContext.Session.Get <string>("SelectedTenantName"); var refreshtoken = await HttpContext.GetTokenAsync("refresh_token").ConfigureAwait(false); accessToken = _commonService.GetAccessTokenWVD(refreshtoken); //await HttpContext.GetTokenAsync("access_token"); var messageStatus = new List <MessageStatus>(); if (data.UserSessions.Where(x => x.IsSelected == true).ToList().Count > 0) { foreach (var item in data.UserSessions.Where(x => x.IsSelected == true).ToList()) { var logOffUserQuery = new LogOffUserQuery() { tenantGroupName = item.tenantGroupName, tenantName = item.tenantName, hostPoolName = item.hostPoolName, sessionHostName = item.sessionHostName, sessionId = item.sessionId, adUserName = item.adUserName }; var Content = new StringContent(JsonConvert.SerializeObject(logOffUserQuery), Encoding.UTF8, "application/json"); _logger.LogInformation($"Service Call to log off user session "); // var response = await client.PostAsync($"SessionHost/LogOffUser", Content); var response = await _userSessionService.LogOffUserSession(accessToken, logOffUserQuery).ConfigureAwait(false); if (response == HttpStatusCode.OK.ToString() || response == "Success") { messageStatus.Add(new MessageStatus() { Message = $"Log off successfully for {item.adUserName} user session.", Status = "Success" }); } else if (response == HttpStatusCode.Forbidden.ToString() || response == HttpStatusCode.Unauthorized.ToString()) { messageStatus.Add(new MessageStatus() { Message = $"Failed to log off {item.adUserName} . You don't have permissions to log off user.", Status = "Error" }); } else { messageStatus.Add(new MessageStatus() { Message = $"Failed to logoff {item.adUserName} user session.", Status = "Error" }); } } ViewBag.ErrorMsg = ""; } else { ViewBag.ErrorMsg = "Please select at least one user"; } await Task.Delay(1500); // delay the process for 1.5 second to get current list of user sessions return(View("ActivityHostDetails", new DiagnoseDetailPageViewModel() { Title = string.Empty, Message = string.Empty, SendMsgStatuses = messageStatus, ConnectionActivity = data.ConnectionActivity, ShowConnectedUser = true, ShowMessageForm = false, UserSessions = await GetUserSessions(accessToken, tenantGroupName, tenant, data.ConnectionActivity.SessionHostPoolName, data.ConnectionActivity.SessionHostName).ConfigureAwait(false), VMPerformance = await GetVMPerformance(data.ConnectionActivity.SessionHostName).ConfigureAwait(false) })); }