public override void Write(byte[] buffer, int offset, int count) { if (buffer.Length == 0) { return; } var ct = HttpContext.Current.Response.ContentType; if (ct.IndexOf("image", StringComparison.OrdinalIgnoreCase) != -1)//图片类型 { filterStream.Write(buffer, offset, count); return; } byte[] newBytes = ReplaceText.Replace(buffer, offset, count); filterStream.Write(newBytes, 0, newBytes.Length); }
public override void Write(byte[] buffer, int offset, int count) { var ct = HttpContext.Current.Response.ContentType; if (ct.IndexOf("image", StringComparison.OrdinalIgnoreCase) != -1) { filterStream.Write(buffer, offset, count); return; } //读出写的文字 byte[] data = new byte[count]; Buffer.BlockCopy(buffer, offset, data, 0, count); string html = Encoding.UTF8.GetString(data); //开始替换 html = ReplaceText.Replace(html); //将替换后的写入response byte[] newdata = Encoding.UTF8.GetBytes(html); filterStream.Write(newdata, 0, newdata.Length); }