;
帖子
3919 
精华
积分
11710 
鱼币
0 ¥ 
来自
大连 
在线时间
1858 小时 
注册时间
2007-6-11 
最后登录
2009-10-20 

贴图大师勋章新人进步勋章宣传大使勋章论坛元老勋章

3
发表于 2009-1-5 19:48 | 只看该作者
Asp.Net鍔ㄦ侀〉闈㈣浆鎴愰潤鎬侀〉闈 - 缂栫▼搴 - Powered by SupeSite

浣犵殑浣嶇疆锛缂栫▼搴 >> 璧勮 >> ASP.NET缂栫▼ >> asp.net瀹炰緥 >> 璇︾粏鍐呭 鍦ㄧ嚎鎶曠ǹ

Asp.Net鍔ㄦ侀〉闈㈣浆鎴愰潤鎬侀〉闈

鍙戝竷: 2008-7-04 13:50 |  浣滆: 缃戠粶杞浇 |   鏉ユ簮: 缃戠粶杞浇 |  鏌ョ湅: 150娆

鍏充簬鍦ˋsp.Net涓姩鎬侀〉闈㈣浆闈欐侀〉闈㈢殑鏂规硶缃戜笂姣旇緝澶氥傜粨鍚堝疄闄呯殑闇姹傦紝鎴戝湪缃戜笂鎵句簡涓浜涙簮浠g爜锛屽苟浣滀慨鏀广傜幇鍦ㄦ妸淇敼鍚庣殑浠g爜浠ュ強璇存槑鍐欎竴涓嬨

涓涓槸涓涓〉闈㈣浆鎹㈢殑绫伙紝璇ョ被閫氳繃闈欐佸嚱鏁癈hangfile锛堬級鏉ュ疄鐜帮紝鍔ㄦ侀〉闈㈠埌闈欐侀〉闈㈢殑杞崲銆

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;

/**//// 锛渟ummary锛
/// 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();
//鍐欒繘鏂囦欢
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);
銆}
銆}
}
銆銆鍦ㄩ〉闈㈡枃浠朵腑锛孎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 ...{
}
}
TAG: Net 鍔ㄦ 闈欐 Asp 椤甸潰
鎵撳嵃 | 鏀惰棌姝ら〉 |  鎺ㄨ崘缁欏ソ鍙 | 涓炬姤
涓婁竴绡 涓嬩竴绡
 

璇勫垎锛0

鍙戣〃璇勮
鏌ョ湅鍏ㄩ儴鍥炲銆愬凡鏈0浣嶇綉鍙嬪彂琛ㄤ簡鐪嬫硶銆