惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News Blog

博客园 - qjlyp

如何用Java 实现 Excel 表达式的解析(摘自:http://topic.csdn.net/t/20030408/17/1634982.html#) 群发UDP的性能测试 (摘自:http://www.cnblogs.com/trywebservice/archive/2008/02/19/1073642.html) 从底层了解ASP.NET体系结构 (http://www.cnblogs.com/rijing2004/archive/2007/09/14/howaspnetwork.html#8) 如何用C#编程方式批量对域控制器添加OU(http://topic.csdn.net/t/20051026/11/4351176.html) C# 高级编程(第3版)--Active Directory编程(http://blog.chinaunix.net/u/884/showart_230743.html) LDAP应用程序接口(http://www.networkdictionary.cn/rfc/rfc1823.php#6) 定制你的LDAP目录的Schema(http://www.infoxa.com/asp/tech_file/xxnr_tech_201.htm) 浅析.Net下Active Directory(AD)编程技术(from :http://www.zysun.com/ldap/21944.html) 活动目录.NET编程Tips(摘:http://www.lupaworld.com/22221/viewspace_17754.html) 应用软件人才体系图 针对构架师的.NET 3.0 框架介绍( 摘自:http://www.chinaaspx.com/dotnet/aspnet/20070811/3489.html) Solving problems while passing XML into a Stored Procedure Rremoting 实现SQL Server 2005快速Web分页 让你的SQL数据库优化使之运行得更快 interoperate beneath C#基础概念二十五问 ASP.Net中利用CSS实现多界面两法【转自:中国站长站】
ASP.NET生成静态HTML页面并分别按年月目录存放[来自:中国站长站]
qjlyp · 2007-06-12 · via 博客园 - qjlyp

一说到新闻系统的话,一定会谈到静态页面生成的,因为静态页面不但是读取速度快,而且又安全;

Chinaz.com

静态页面的生成不管是小到现在的企业网站大至网易,QQ等门户都用到了; Chinaz.com

那么我们如何来生成静态页呢?

[中国站长站]

以什么方式生成静态页面呢……

[中国站长站]

在生成静态页面的时候有那些是要注意的呢: [中国站长站]

静态页面命名

[中国站长站]

统一存放目录

[中国站长站]

静态页面模板

Chinaz.com

页面生成 [中国站长站]

一般来说,在原来新闻系统的基础上我们可以根据GET此页面请求的内容再生成(比如:http;//www.test.com/news.aspx?id=1,GET此页面代码直接写至一个文本文件并以HTML命名即可); Chinaz.com

在这里我所采用的是模板生成,先用DW做一个网页模板,将标题,内容等将要动态实现的内容先以$Title$等替换,等在生成的时候替换成新闻的内容; Chinaz.com

命名:在生成的时候一般来说是采用新闻发布的时间转换成的字符串,这个是不会重复的。另外我还按年份月份把这些静态文件存放在不同的目录,以便于管理,在这里根据一个新闻的ID调用方法WriteNews()给定参数ID,它就会根据此ID从数据库中读取内容,再根据静态模板页面html/test.html生成新的静态页面存放在相应年份月份的目录

[中国站长站]

好了,下面是代码: Chinaz.com

以下为引用的内容:

using System;
using System.IO;
using System.Web;
using System.Text;
namespace PowerLeader.Components
...{
    /**//// <summary>
    /// WriteTOHtml 的摘要说明。
    /// </summary>
    public class WriteTOHtml
    ...{
        public WriteTOHtml()
        ...{
            //
            // TODO: 在此处添加构造函数逻辑

Chinaz.com


            //
        } Chinaz.com

        public static void WriteNews(int id)
        ...{
            News news = new News();           
            News.NewsDetails newsDetails = new PowerLeader.Components.News.NewsDetails();
            newsDetails = news.GetNews(id);
            bool flag;
            flag = WriteFile(newsDetails);
        } [中国站长站]

        public static bool WriteFile(News.NewsDetails newsDetails)
        ...{
            Directory.CreateDirectory(HttpContext.Current.Server.MapPath("/PowerLeader/html/"+newsDetails.addtime.ToString("yyyy")+"/"+newsDetails.addtime.ToString("MM")));
            string path = HttpContext.Current.Server.MapPath("../html/"+newsDetails.addtime.ToString("yyyy")+"/"+newsDetails.addtime.ToString("MM")+"/");
            Encoding code = Encoding.GetEncoding("gb2312");
            // 读取模板文件
            string temp = HttpContext.Current.Server.MapPath("../html/text.html");

Chinaz.com


            StreamReader sr = null;
            StreamWriter sw = null;
            string stringTempCode = ""; 
            try
            ...{
                sr = new StreamReader(temp, code);
                stringTempCode = sr.ReadToEnd(); // 读取文件
            }
            catch(Exception exp)
            ...{
                HttpContext.Current.Response.Write(exp.Message);

Chinaz.com


                HttpContext.Current.Response.End();
                sr.Close();
            }  
            string htmlFileName = newsDetails.addtime.ToString("yyyyMMddHHmmss") + ".html";
            // 替换内容
            // 这时,模板文件已经读入到名称为str的变量中了
            stringTempCode = stringTempCode.Replace("$PageTitle$","抗战OnLine官方网站...");
            stringTempCode = stringTempCode.Replace("$Type$",newsDetails.type.ToString().Trim());

Chinaz.com


            stringTempCode = stringTempCode.Replace("$Author$",newsDetails.author.ToString().Trim());
            stringTempCode = stringTempCode.Replace("$From$",newsDetails.from.Trim());
            stringTempCode = stringTempCode.Replace("$Time$",newsDetails.addtime.ToString().Trim());
            stringTempCode = stringTempCode.Replace("$Title$",newsDetails.title.Trim());
            stringTempCode = stringTempCode.Replace("$Content$",newsDetails.content);
            // 写文件
            try
            ...{ Chinaz.com
                sw = new StreamWriter(path + htmlFileName , false, code);
                sw.Write(stringTempCode);
                sw.Flush();
            }
            catch(Exception ex)
            ...{
                HttpContext.Current.Response.Write(ex.Message);
                HttpContext.Current.Response.End();
            }
            finally Chinaz.com
            ...{
                sw.Close();
            }
            return true;
        }
    }
}

Chinaz.com