投稿 评论 顶部

asp.net网页静态化

佚名 网络安全

一。①:首先要有这个文件URLRewriter.dll,如果没有,赶快到网上下载一个,并将其放到下面的bin目录里面,并且将其引用添加到下面里面;

? ②:下面就是Web.Config文件的配置了,当然,配置过程相当简单:

? 1:先添加这个

<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
<RewriterConfig>
? <Rules>
? <!-- Rules for Blog Content Displayer -->
? <RewriterRule>
? <LookFor>~/(.[0-9]*)/.html</LookFor>
? <SendTo>~/ArticleDetail.aspx?MyID=$1</SendTo>
? </RewriterRule>
? </Rules>
</RewriterConfig>

? 2:再添加这个

? <httpHandlers>
? <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
? <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
? </httpHandlers>

? 至此,已成功一大半,上面两个都添加到Web.Config,添加到什么位置看来没必要讲了!

? 最后一步:在IIS中找到自己的虚拟目录网站,点属性,然后点配置,然后弹出应用程序配置对话框,选择添加,添加的可执行文件路径为c:/windows/microsoft.net/framework/v2.0.50727/aspnet_isapi.dll,扩展名为.html(如果是虚拟主机,可购买使用九网互联的主机,可直接在线操作开通伪静态

二。

view plaincopy to clipboardprint?
using System;??
using System.Data;??
using System.Configuration;??
using System.Collections;??
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.IO;??
namespace Web.Admin??
{??
??? public partial class Admin_MakeIndex : System.Web.UI.Page??
??? {??
??????? protected void Page_Load(object sender, EventArgs e)??
??????? {??
??????????? CommFun.IsAdmin();??
??????????? if (!IsPostBack)??
??????????? {??
??????????????? string url = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.LastIndexOf("/admin")); //获取网址??
??????????????? url += "/default.aspx"; //首页文件??
??????????????? string text;??
??????????????? System.Net.WebRequest wReq = System.Net.WebRequest.Create(url);??
??????????????? System.Net.WebResponse wResp = wReq.GetResponse();? //注意要先 using System.IO;??
??????????????? System.IO.Stream respStream = wResp.GetResponseStream();??
??????????????? System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("gb2312"));??
??????????????? text = reader.ReadToEnd();??
??????????????? string path = System.Web.HttpContext.Current.Server.MapPath("../default.html");??
??????????????? using (System.IO.StreamWriter sw = new System.IO.StreamWriter(path, false, System.Text.Encoding.UTF8))??
??????????????? {??
??????????????????? if (text.Trim() != "")??
??????????????????? {??
??????????????????????? sw.Write(text);??
??????????????????????? Response.Write("首页生成成功!");??
??????????????????? }??
??????????????? }??
??????????? }??
??????? }??
??? }??
}?
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.IO;
namespace Web.Admin
{
??? public partial class Admin_MakeIndex : System.Web.UI.Page
??? {
??????? protected void Page_Load(object sender, EventArgs e)
??????? {
??????????? CommFun.IsAdmin();
??????????? if (!IsPostBack)
??????????? {
??????????????? string url = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.LastIndexOf("/admin")); //获取网址
??????????????? url += "/default.aspx"; //首页文件
??????????????? string text;
??????????????? System.Net.WebRequest wReq = System.Net.WebRequest.Create(url);
??????????????? System.Net.WebResponse wResp = wReq.GetResponse();? //注意要先 using System.IO;
??????????????? System.IO.Stream respStream = wResp.GetResponseStream();
??????????????? System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("gb2312"));
??????????????? text = reader.ReadToEnd();
??????????????? string path = System.Web.HttpContext.Current.Server.MapPath("../default.html");
??????????????? using (System.IO.StreamWriter sw = new System.IO.StreamWriter(path, false, System.Text.Encoding.UTF8))
??????????????? {
??????????????????? if (text.Trim() != "")
??????????????????? {
??????????????????????? sw.Write(text);
??????????????????????? Response.Write("首页生成成功!");
??????????????????? }
??????????????? }
??????????? }
??????? }
??? }
}
?

三、同二类似只是把模板分成很多小的部分,生成时拼接小的模板,如头部、版权等等,这个方法可以参照211news新闻发布系统的做法。

四、利用js-ajax,例子如下:
? <script>??
? var oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");??
? oXmlHttp.open("GET","http://www.163.com", false);??
? oXmlHttp.send()??
? var oStream = new ActiveXObject("ADODB.Stream");??
? if(oStream == null)??
? alert("您的机器不支持ADODB.Stream.")??
? else??
? {??
? oStream.Type=1;??
? oStream.Mode=3;??
? oStream.Open() ;??
? oStream.Write(oXmlHttp.responseBody);??
? oStream.Position= 0;??
? oStream.Type= 2;??
? oStream.Charset="gb2312";??
? var result= oStream.ReadText();??
? oStream.Close();??
? oStream = null;??
? var aa = window.open("","")??
? document.write(result);??
? aa.document.write(result);??
? }??
? </script>