asp.net网站如何生成静态页面 本帖最后由 zky0901 于 2012-06-26 09:30:32 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这种直接使用模块替换的方法。在添加时直接生成HTML 单个页面替换我有些知道了,但那边连接如何也处理成html页面呢,如列表页中的连接如何才能连接到那些html页呢 你执行分页操作的时候是一个请求。可以做成ajax效果分页。每次点击请求一个json。一般列表页面也用不着静态化的。用的话一般就是评论什么的,用ajax分页。 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Static.aspx.cs" Inherits="Article.Static" %><%@ Import Namespace="System.IO" %><script runat="server"> protected void Button1_Click(object sender, EventArgs e) { StringWriter wr = new StringWriter(); Server.Execute(this.TextBox1.Text, wr); //你可以使用第三个参数传递页面的更多初始数据 this.Label1.Text = Server.HtmlEncode(wr.ToString()); File.WriteAllText(Server.MapPath(this.TextBox2.Text), wr.ToString()); }</script><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>演示取得当前网站中其它网页的源代码只需要两行代码就够了 </title></head><body> <form id="form1" runat="server" defaultbutton="Button1"> <div> 请输入本网站的页面名称: <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox> <br /> 请输入目标文件名称 <asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox> <br /> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> <hr /> <asp:Label ID="Label1" runat="server" Text="Label"> </asp:Label> </div> </form></body></html>以上代码可以生成HTML静态页,可以按需求在添加(新闻)的时候在后台自动生成一个HTML静态页。要更新的话只需要在更新(新闻)的时候,重新生成该HTML静态页就行了。问:列表页中的连接如何才能连接到那些html页呢?答:可以在数据库中添加一个字段,用来保存链接的地址。 <LookFor>index.html</LookFor><SendTo>default.aspx<SendTo> <LookFor>~/xxx_(\d{1,3})_(\d{1,4}).html</LookFor> <SendTo>~/xxx.aspx?gameid=$1&serverid=$2</SendTo>这是带参数的! http://www.sudu.cn/info/html/edu/20071025/318887.html AJAX终极问题~~有经验的都来爽爽! 完成:我把鼠标移动到控件的图片上时,图片就放大,鼠标离开时,图片就缩小 站点访问量,最高占线,当前占线要怎么做 dropdownlist绑定数据后写入只能是第一行。 想做一个抓取为原理的搜索 急寻:vs2003中的public类,及public static string变量,在VS2005中不能用了! 有石家庄的程序员吗?谁业余有时间,快速我和我联系。 如何动态绑定类的属性和控件值 Shell函数问题,急!急!急! 图片保存出错了 win2003安装.NET的错误??????? 字符串不固定的情况下如何放到集合里
protected void Button1_Click(object sender, EventArgs e)
{
StringWriter wr = new StringWriter();
Server.Execute(this.TextBox1.Text, wr); //你可以使用第三个参数传递页面的更多初始数据
this.Label1.Text = Server.HtmlEncode(wr.ToString());
File.WriteAllText(Server.MapPath(this.TextBox2.Text), wr.ToString());
}
</script><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>演示取得当前网站中其它网页的源代码只需要两行代码就够了 </title>
</head>
<body>
<form id="form1" runat="server" defaultbutton="Button1">
<div>
请输入本网站的页面名称:
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<br />
请输入目标文件名称
<asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<hr />
<asp:Label ID="Label1" runat="server" Text="Label"> </asp:Label>
</div>
</form>
</body>
</html>
以上代码可以生成HTML静态页,可以按需求在添加(新闻)的时候在后台自动生成一个HTML静态页。要更新的话只需要在更新(新闻)的时候,重新生成该HTML静态页就行了。问:列表页中的连接如何才能连接到那些html页呢?
答:可以在数据库中添加一个字段,用来保存链接的地址。
<SendTo>default.aspx<SendTo>
<LookFor>~/xxx_(\d{1,3})_(\d{1,4}).html</LookFor>
<SendTo>~/xxx.aspx?gameid=$1&serverid=$2</SendTo>这是带参数的!