cite bite如何实现它的缓存?

How does cite bite achieve it's cache?

任何人都可以阐明 citebite 如何实现它的缓存,特别是它如何能够显示与原始页面具有相同布局的缓存?

我希望实现非常相似的目标:我使用

从源中提取了 html
public static string sourceCache (string URL)
{
        string sourceURL = URL;
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sourceURL);
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        if (response.StatusCode == HttpStatusCode.OK)
        {
            Stream receiveStream = response.GetResponseStream();
            StreamReader readStream = null;

            if (response.CharacterSet == null)
            {
                readStream = new StreamReader(receiveStream);
            }
            else
            {
                readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
            }

            string data = readStream.ReadToEnd();

            response.Close();
            readStream.Close();

            return data;
        }

        return "couldn't retrieve cache";
    }
}

然后我发送到我的数据库存储为 nvarchar(max)。加载页面显示缓存时,我拉取该字段并将其设置为div 属性.

的innerhtml

但是,在 citebite 上,他们的缓存保留了源页面的样式和布局,而我的则没有。

我哪里错了?

我有一个 asp.net 4.5 c# web 表单网站

为此页面创建一个,查看源代码。秘密是

<base href="" />

The HTML Base Element () specifies the base URL to use for all relative URLs contained within a document.There is maximum one element in a document.

根据上面的@Alex K,基本元素似乎是问题所在。

我已经修改了代码以检查现有的 html 中是否有 "base href",如果没有插入 href 设置为源的基本元素 url

public static string sourceCache (string URL)
    {
        string sourceURL = URL;
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sourceURL);
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        if (response.StatusCode == HttpStatusCode.OK)
        {
            Stream receiveStream = response.GetResponseStream();
            StreamReader readStream = null;

            if (response.CharacterSet == null)
            {
                readStream = new StreamReader(receiveStream);
            }
            else
            {
                readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
            }

            string data = readStream.ReadToEnd();

            response.Close();
            readStream.Close();

            if (data.Contains("base href"))
            {
                return data;
            }
            else
            {
                //we need to insert the base href with the source url
                data = basecache(data, URL);
                return data;
            }                
        }

        return "couldn't retrieve cache";
    }

    public static string basecache (string htmlsource, string urlsource)
    {
        //make sure there is a head tag
        if (htmlsource.IndexOf("<head>") != -1)
        {
            int headtag = htmlsource.IndexOf("<head>");
            string newhtml = htmlsource.Insert(headtag + "<head>".Length, "<base href='" + urlsource + "'/>");
            return newhtml;
        }
        else if(htmlsource.IndexOf("&lt;head&gt;") != -1)
        {
            int headtag = htmlsource.IndexOf("&lt;head&gt;");
            string newhtml = htmlsource.Insert(headtag + "&lt;head&gt;".Length, "<base href='" + urlsource + "'/>");
            return newhtml;
        }
        else
        {
            return htmlsource;
        }
    }

到目前为止,我只在几个 sites/domains 上测试过它,但它似乎有效,非常感谢 Alex 的帮助。