A wall girl uses response. Filter to solve the Google CDN problem in stackexchange. Exceptional.

Source: Internet
Author: User

A wall on the ancient road, some open-source Dongdong uses the ancient road CDN, such as predictional and opserver, which leads to slow or unusable services.

Must be replaced

Predictional only needs to replace the page with response. filter, because you have to regularly merge the pages to maintain versions.

Internal class responsestream: memorystream {# region ctor private stream output {Get; set;} public httpcontextbase context {Get; set ;} /// <summary> // stream buffer output on the page /// </Summary> public list <byte> bytesarray {Get; set;} public responsestream (httpcontextbase context) {context = context; Output = context. response. filter; context. response. bufferoutput = true; context. response. buffer = True; bytesarray = new list <byte> () ;}# endregion public override void write (byte [] buffer, int offset, int count) {If (context. response. contenttype! = "Text/html") {output. write (buffer, offset, count); return;} bytesarray. addrange (buffer);} public override void close () {If (bytesarray. count> 0) closebyreplace (); output. close (); base. close ();} private void closebyreplace () {var html = encoding. utf8.getstring (bytesarray. toarray (), 0, bytesarray. count); var sb = new stringbuilder (HTML); sb. replace ("// ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js", "http://libs.baidu.com/jquery/1.7.2/jquery.min.js"); var outputbytes = encoding. utf8.getbytes (sb. tostring (); output. write (outputbytes, 0, outputbytes. length );}}

The corresponding action is changed:

        public ActionResult Exceptions()        {            var context = System.Web.HttpContext.Current;            context.Response.Filter = new ResponseStream(HttpContext);            var page = new HandlerFactory().GetHandler(context, Request.RequestType, Request.Url.ToString(),                Request.PathInfo);            page.ProcessRequest(context);            return null;        }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.