示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string imgid = Request["imgid"];
            string mdUrl = "https://github.com/fhtino/aspnetstuff/blob/master/RenderGitHubMD/mdsample/sample1.md";

            var githubMDProxy = new GitHubMDProxy(mdUrl);

            if (imgid == null)
            {
                string cacheKey     = "my-html-" + mdUrl;
                string htmlFragment = Cache[cacheKey] as string;
                if (htmlFragment == null)
                {
                    htmlFragment = githubMDProxy.GetHtml("full.aspx?imgid=").Result;
                    Cache.Insert(cacheKey, htmlFragment, null, DateTime.UtcNow.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration);
                }
                ContentDiv.InnerHtml     = htmlFragment;
                LinkToSource.NavigateUrl = mdUrl;
                LinkToSource.Text        = mdUrl;
            }
            else
            {
                string cacheKeyIMG = "my-img_" + imgid;
                string cacheKeyCT  = "my-img_" + imgid + "_ct";
                byte[] imgBody     = Cache[cacheKeyIMG] as byte[];
                string contentType = Cache[cacheKeyCT] as string;

                if (imgBody == null || contentType == null)
                {
                    Tuple <byte[], string> imageData = githubMDProxy.GetImage(imgid).Result;
                    imgBody     = imageData.Item1;
                    contentType = imageData.Item2;
                    Cache.Insert(cacheKeyIMG, imgBody, null, DateTime.UtcNow.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration);
                    Cache.Insert(cacheKeyCT, contentType, null, DateTime.UtcNow.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration);
                }

                Response.Clear();
                Response.ContentType = contentType;
                Response.OutputStream.Write(imgBody, 0, imgBody.Length);
                Response.End();
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string mdUrl = "https://github.com/fhtino/aspnetstuff/blob/master/RenderGitHubMD/mdsample/sample1.md";

            string imgid = Request["imgid"];

            var githubMDProxy = new GitHubMDProxy(mdUrl);

            if (imgid == null)
            {
                ContentDiv.InnerHtml = githubMDProxy.GetHtml("?imgid=").Result;
            }
            else
            {
                Tuple <byte[], string> imageData = githubMDProxy.GetImage(imgid).Result;
                byte[] imgBody     = imageData.Item1;
                string contentType = imageData.Item2;

                Response.Clear();
                Response.ContentType = contentType;
                Response.OutputStream.Write(imgBody, 0, imgBody.Length);
                Response.End();
            }
        }