/// <summary> /// 重新载入用户信息 /// </summary> public void ReloadLoginUserInfo(Guid token) { try { BusinessContext.Current.LoginUser = LoadUser(HttpContext.Current == null ? "::1" : HttpContext.Current.Request.UserHostAddress, token); } catch (Exception ex) { BusinessContext.Current.LoginUser = LoginUser.Anymouse; LogRecorder.Record(ex.ToString()); } }
/// <summary> /// 取当前登录用户信息 /// </summary> /// <returns></returns> public static Guid GetLoginUserInfo() { var cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; if (string.IsNullOrEmpty(cookie?.Value)) { return(Guid.Empty); } try { var formsAuthentication = FormsAuthentication.Decrypt(cookie.Value); Guid token; return(Guid.TryParse(formsAuthentication?.UserData, out token) ? token : Guid.Empty); } catch (Exception ex) { LogRecorder.Record(ex.ToString()); return(Guid.Empty); } }
/// <summary> /// 请求注册为代码 /// </summary> private void RecordRequestToCode(HttpRequestMessage request) { StringBuilder code = new StringBuilder(); if (request.Method == HttpMethod.Get) { code.Append($"\r\n {{\r\n caller.Bear = \"{ExtractToken(request)}\";\r\n var result = caller.Get/*<>*/(\"{request.RequestUri}\");\r\n Console.WriteLine(JsonConvert.SerializeObject(result));\r\n }}"); } else { Task <string> task = request.Content.ReadAsStringAsync(); task.Wait(); LogRecorder.MonitorTrace($"Content:{task.Result}"); code.Append($"\r\n {{\r\n caller.Bear = \"{ExtractToken(request)}\";\r\n var result = caller.Post/*<>*/(\"{request.RequestUri}\", new Dictionary<string, string>\r\n {{"); foreach (KeyValuePair <string, string> item in FormatParams(task.Result)) { code.Append($"\r\n {{\"{item.Key}\",\"{item.Value}\"}},"); } code.Append("\r\n });\r\n Console.WriteLine(JsonConvert.SerializeObject(result));\r\n }"); } LogRecorder.Record(code.ToString()); }
/// <summary> /// 请求注册为代码 /// </summary> private void RecordRequestToCode(HttpRequestMessage request) { var code = new StringBuilder(); if (request.Method == HttpMethod.Get) { code.Append($@" {{ caller.Bear = ""{ExtractToken(request)}""; var result = caller.Get/*<>*/(""{request.RequestUri}""); Console.WriteLine(JsonConvert.SerializeObject(result)); }}"); } else { var task = request.Content.ReadAsStringAsync(); task.Wait(); LogRecorder.MonitorTrace($"Content:{task.Result}"); code.Append($@" {{ caller.Bear = ""{ExtractToken(request)}""; var result = caller.Post/*<>*/(""{request.RequestUri}"", new Dictionary<string, string> {{"); var di = FormatParams(task.Result); foreach (var item in di) { code.Append($@" {{""{item.Key}"",""{item.Value}""}},"); } code.Append(@" }); Console.WriteLine(JsonConvert.SerializeObject(result)); }"); } LogRecorder.Record(code.ToString()); }