Asp.net动态转静态页面的两种方法总结
///Asp.net动态转静态页面的两种方法总结
///由于搜索引擎对aspx页面收录和html页面的收录率的差别以及页面资源占用问题,我们很多时候需要
///实现aspx页面动态转静态。两种主流方法如下:
///第一张方法:
///使用模板转换,步骤如下:
///1,建立Myconvert.cs 类文件
using System;
//记得添加以下三个引用
using System.Text;
using System.Web;
using System.IO;
namespace TesConvert
{
///
///MyConvert的摘要说明。
///
public class MyConvert
{
public MyConvert()
{
//在此添加构造函数逻辑
}
public bool WriteFile(string strText,string strContent,string strAuthor)
{
string path=HttpContext.Current.Server.MapPath("/TesConvert/news/");//定义html文件存放路径
Encoding code=Encoding.GetEncoding("gb2312");//定义文字编码
//读取模板文件
string temp=HttpContext.Current.Server.MapPath("TesConver/text.html");
StreamReader sr=null;
StreamWriter sw=null;
string str="";
try{
sr=new StreamReader(temp,code);
str=sr.ReadToEnd();//读取文件
}catch(Exception exp){
HttpContext.Current.Response.Write(exp.Message);
HttpContext.Current.Response.End();
sr.Close();
}
string htmlfilename=path+DateTime.Now.ToString("yyyyMMddHHmmss")+".html";
//替换内容
//这时,模板文件已经读入到名称为str的变量中了
str=str.Replace("ShowArticle",strText);//模板页中的ShowArticle
str=str.Replace("title",strText);
str=str.Replace("content",strContent);
str=str.Replace("author",strAuthor);
//写文件
try{
sw=new Strea
相关文档:
public class SqlCheck
{
public SqlCheck()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public SqlConnection oconn()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["StudyConnectionString"] ......
理论和实践不一样,理论再好,也要能实践才行。
如果你从来没有写过程序,那么,在写程序之前还是先看看语法之类的基础;如果你写过程序,那么你就可以边写程序边学习。
无论用什么语言写一个网站,其根本都是差不多,无非就是对数据库的操作,如插入、删除、修改和查询。
类并不可怕。类无非就是一些函数和属性,而且 ......
使用 ASP.NET TreeView 控件可以轻松地绑定到支持 IHierarchicalDataSource 接口的数据源,例如:XmlDataSource 类和 SiteMapDataSource 类。此外,您还可以完全控制将数据源的哪些字段用于 Text、Value 和其他 TreeNode 属性。
一、绑定到 XML 文件
TreeView 控件支持到 XML ......
TreeView 控件具有许多不同的外观,从而可以提供灵活的图像自定义以及指定自定义用户界面 (UI) 选项的属性。您可以将图像与 TreeView 控件一起使用来表示节点、连接线以及展开和折叠图标。还可以使用 ImageSet 属性中一组预定义的图像,或者通过设置各个图像属性来使用自定义图像。
&nbs ......
... 前言
在Web应用程序中,引入AJAX,不仅可以提高用户体验(页面局部刷新),而且可以在一定程度上,降低Web服务器的工作负载和响应时间。
AJAX 使用Javascript,在客户端(浏览器端),通过Http(s)协议,向服务器端 (Web Server)发起请求;服务器根据请求的URI,
完成相应的逻辑操作,尔后将执行的 ......