Exemple #1
0
 void ReplaceOutput()
 {
     //如果项目需要部署成子应用程序,则开启,否则不需要开启(可注释掉下面一行代码)
     //要处理自定义语言标签
     if (WebHelper.IsAriesSuffix())
     {
         if (AppConfig.IsAspNetCore)
         {
             string path = AppConfig.WebRootPath + HttpContext.Current.Request.Url.LocalPath;
             if (File.Exists(path))
             {
                 byte[] data = File.ReadAllBytes(path);
                 if (data != null && data.Length > 0)
                 {
                     byte[] newData = ReplaceText.Replace(data, 0, data.Length);
                     context.Response.ContentType = "text/html";
                     context.Response.BinaryWrite(newData);
                 }
             }
         }
         else
         {
             context.Response.Filter = new HttpResponseFilter(context.Response.Filter);
         }
     }
 }
        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);
        }