国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Asp.Net中動態(tài)頁面轉(zhuǎn)靜態(tài)頁面_.Net教程

2024-07-10 12:50:42
字體:
供稿:網(wǎng)友

推薦:Asp.net 備份和還原SQL Server及壓縮Access數(shù)據(jù)庫
* * 功能說明:備份和恢復(fù)SQL Server數(shù)據(jù)庫 * 作者: 劉功勛; * 版本:V0.1(C#2.0);時間:2007-1-1 * 當(dāng)使用SQL Server時,請引用 COM組件中

關(guān)于在Asp.Net中動態(tài)頁面轉(zhuǎn)靜態(tài)頁面的方法網(wǎng)上比較多。結(jié)合實(shí)際的需求,我在網(wǎng)上找了一些源代碼,并作修改。現(xiàn)在把修改后的代碼以及說明寫一下。

一個是一個頁面轉(zhuǎn)換的類,該類通過靜態(tài)函數(shù)Changfile來實(shí)現(xiàn),動態(tài)頁面到靜態(tài)頁面的轉(zhuǎn)換。

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;

/**//// <summary>
/// Summary description for HtmlProxy
/// </summary>
public class HtmlProxy
...{
public HtmlProxy()
...{
}
public static bool ChangeFile(int id)
...{
string filename = HttpContext.Current.Server.MapPath("Post_" id ".html");
//嘗試讀取已有文件
Stream st = GetFileStream(filename);
//如果文件存在并且讀取成功
if (st != null)
...{
using (st)
...{
StreamToStream(st, HttpContext.Current.Response.OutputStream);
return true;
//Response.End();
}
}
else
...{
StringWriter sw = new StringWriter();
HttpContext.Current.Server.Execute("ForumDetail.aspx?PID=" id, sw);

string content = sw.ToString();
//寫進(jìn)文件
try
...{
using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Write))
...{
using (StreamWriter stw = new StreamWriter(fs, HttpContext.Current.Response.ContentEncoding))
...{
stw.Write(content);
}
}
 return true;
}
catch ...{ return false; }
}
}

private static Stream GetFileStream(string filename)
...{
try
...{
DateTime dt = File.GetLastWriteTime(filename);
TimeSpan ts = dt - DateTime.Now;
if (ts.TotalHours >1)
...{
//一小時后過期
return null;
}
return new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
}
catch ...{ return null; }
}
static public void StreamToStream(Stream src, Stream dst)
...{
  byte[] buf = new byte[4096];
  while (true)
...{
int c = src.Read(buf, 0, buf.Length);
if (c == 0)
return;
dst.Write(buf, 0, c);
 }
 }
}
  在頁面文件中,F(xiàn)orURL.aspx的后臺代碼如下:
protected void Page_Load(object sender, EventArgs e)
...{
try
...{
int id = int.Parse(Request.QueryString["PID"]);
if(HtmlProxy.ChangeFile(id))
...{
 Response.Redirect("Post_" id ".html");
}
 else
...{
 Response.Redirect("Post.aspx?PID=" id );
}
}
 catch ...{
}
}

分享:VS 2008和.NET 3.5 Beta2常見問題的解決方案
自我們發(fā)布VS 2008和.NET 3.5的Beta2版本以來,已經(jīng)有一個多星期了。到目前為止,來自使用者的反饋非常之好。我收到了很多電郵,稱之為我們發(fā)布過的最好的beta,有幾個人已經(jīng)全時使用它來做所有

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 盘锦市| 镇原县| 西昌市| 亚东县| 当涂县| 永嘉县| 延安市| 宝丰县| 阜南县| 宝坻区| 怀仁县| 含山县| 瑞丽市| 中超| 新源县| 镇巴县| 兴仁县| 常宁市| 钟祥市| 镶黄旗| 龙门县| 寿阳县| 綦江县| 昌图县| 油尖旺区| 苏尼特左旗| 古交市| 株洲市| 肥西县| 宁蒗| 潜江市| 博爱县| 安福县| 固原市| 自贡市| 上栗县| 高清| 海口市| 隆子县| 尤溪县| 徐水县|