/// <summary> /// 重写JSON.NET的方法 /// </summary> /// <param name="writer"></param> /// <param name="value"></param> /// <param name="serializer"></param> public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { XmlCdata data = value as XmlCdata; if (data != null) { writer.WriteValue(data.Value); } }
public void Test_XmlCdata_implicit() { XmlCdata data = "abc"; // 隐式类型转换 Assert.AreEqual("abc", data.Value); Assert.AreEqual("abc", data.ToString()); var schema = (data as IXmlSerializable).GetSchema(); Assert.IsNull(schema); string s = data; Assert.AreEqual("abc", s); }
public void Test_XmlCdata_Equals() { XmlCdata data = "abc"; // 隐式类型转换 XmlCdata data2 = new XmlCdata("abc"); Assert.IsTrue(data == data2); Assert.IsTrue(data.Equals(data2)); object a = data; object b = data2; Assert.IsTrue(a.Equals(b)); Assert.IsTrue(a.GetHashCode() == b.GetHashCode()); XmlCdata data3 = "ab"; Assert.IsTrue(data != data3); }
private void GetSession(HttpContext context) { if (context.Session != null) { StringBuilder sb = new StringBuilder(); sb.AppendLine(); foreach (string sessionKey in context.Session.Keys) { object sessionValue = context.Session[sessionKey]; if (sessionValue == null) { sb.AppendFormat("{0}: NULL\r\n", sessionKey); } else { sb.AppendFormat("{0}: ({1}) {2}\r\n", sessionKey, sessionValue.GetType().Name, sessionValue); } } this.Session = sb.ToString(); } }
/// <summary> /// 设置请求信息 /// </summary> private void SetHttpInfo(HttpContext context) { if (context == null) { return; } if (context.Request.IsAuthenticated) { this.UserName = context.User.Identity.Name; } this.Url = context.Request.Url.ToString(); this.RawUrl = context.Request.RawUrl; if (context.Request.Browser != null) { this.Browser = context.Request.Browser.Browser + context.Request.Browser.MajorVersion; } string postData = null; // 这里可能会有一个安全漏洞,应该可能会记录一些敏感信息 if (context.Items[IgnoreHttpsRequestBody] == null) { if (context.Request.RequestType == "POST") { if (context.Request.Files.Count == 0) { postData = context.Request.ReadInputStream(); context.Request.InputStream.Position = 0; } else { StringBuilder sb = new StringBuilder(); foreach (string name in context.Request.Form.AllKeys) { string[] values = context.Request.Form.GetValues(name); if (values != null) { foreach (string value in values) { sb.AppendFormat("&{0}={1}", HttpUtility.UrlEncode(name), HttpUtility.UrlEncode(value)); } } } if (sb.Length > 0) { sb.Remove(0, 1); postData = sb.ToString(); } } } } if (context.Request.Headers.Count > 0) { StringBuilder sb = new StringBuilder(); sb.AppendLine() .Append(context.Request.RequestType) .Append(" ") .Append(context.Request.Url.ToString()) .AppendLine(" HTTP/1.1"); foreach (string key in context.Request.Headers.AllKeys) { string value = context.Request.Headers[key]; sb.Append(key).Append(": ").Append(value).AppendLine(); } if (postData != null) { sb.AppendLine().AppendLine(postData); } this.RequestText = sb.ToString(); } if (context.Session != null) { StringBuilder sb = new StringBuilder(); sb.AppendLine(); foreach (string sessionKey in context.Session.Keys) { object sessionValue = context.Session[sessionKey]; if (sessionValue == null) { sb.AppendFormat("{0}: NULL\r\n", sessionKey); } else { sb.AppendFormat("{0}: ({1}) {2}\r\n", sessionKey, sessionValue.GetType().Name, sessionValue); } } this.Session = sb.ToString(); } }