Asp.net生成静态页面原理
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
namespace menutest
{
///
/// Conn 的摘要说明。
///
// by kyo
// 此类是生成静态网页的小程序
public class Conn
{
public Conn()
{
}
public static bool WriteFile(string strText,string strContent,string strAuthor)
{
string path = HttpContext.Current.Server.MapPath("/menutest/");
Encoding code = Encoding.GetEncoding("gb2312");
// 读取模板文件
string temp = HttpContext.Current.Server.MapPath("/menutest/news/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=DateTime.Now.ToString("yyyyMMddHHmmss")+".html";
string htmlfilename="kyo.html";
// 替换内容
// 这时,模板文件已经读入到名称为str的变量中了
str = str.Replace("ShowArticle",strText); //模板页中的ShowArticle
str = str.Replace("biaoti",strText);
str = str.Replace("content",strContent);
str = str.Replace("author",strAuthor);
// 写文件
try
{
&#
相关文档:
//private string datapatch = ConfigurationSettings.AppSettings["acessconn"];//数据库地址
private string datapatch = "db/global.asa";//数据库地址
///
/// 取得dataset
//
/// 查询语句
///
public DataSet GetDataSet(string Commandtext)
{&nbs ......
在web config中 作如下配置:
<connectionStrings>
<add name="ydycon" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=|DataDirectory|ydy.mdb" providerName="System.Data.OleDb"/>
</connectionStrings>
在.net文件中应用链接 ......
第一:
private void Button1_Click( object sender, System.EventArgs e ) { Response.Redirect( Request.Url.ToString( ) ); } 第二:
private void Button2_Click( object sender, System.EventArgs e ) { Response.Write( " < script language=javascript>window.location.href=document.URL; < /script&g ......
高效使用使用SQL缓存依赖
ASP.NET Framework新增的一个非常强大的功能是SQL缓存依赖。该功能允许底层数据库中的数据修改时,自动地重新载入缓存的数据。
在使用绝对缓存过期策略或者弹性缓存过期策略时有一个权衡,对于性能和陈旧数据的权衡。例如,如果在内存中缓存数据20秒,则这20秒内显示的数据可能是� ......
原帖地址:http://www.wangchao.net.cn/bbsdetail_572426.html
简介
有许多聪明的办法可以解决HTTP协议的无状态问题,例如对每个请求重复发送应用程序数据包、使用HTTP认证机制来将请求映射到特定的用户、使用Cookie来存储一系列请求的状态等。在ASP.net技术中提供了 ......