发布于 2016-06-08 04:06:10 | 134 次阅读 | 评论: 0 | 来源: 网友投递
ASP.NET
ASP.NET 是.NET FrameWork的一部分,是一项微软公司的技术,是一种使嵌入网页中的脚本可由因特网服务器执行的服务器端脚本技术,它可以在通过HTTP请求文档时再在Web服务器上动态创建它们。 指 Active Server Pages(动态服务器页面) ,运行于 IIS(Internet Information Server 服务,是Windows开发的Web服务器)之中的程序 。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtContent" runat="server" Height="179px" TextMode="MultiLine" Width="350px"></asp:TextBox><br />
<br />
<asp:Button ID="btnMake" runat="server" OnClick="btnMake_Click" Text="生成静态页" />
</div>
</form>
</body>
</html>
protected void btnMake_Click(object sender, EventArgs e)
{
//替换掉模板中的特征字符
string mbPath = Server.MapPath("template.htm");
Encoding code = Encoding.GetEncoding("UTF-8");
StreamReader sr = null;
StreamWriter sw = null;
string str = null;
//读取
try
{
sr = new StreamReader(mbPath, code);
str = sr.ReadToEnd();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sr.Close();
}
//根据时间自动重命名,扩展名也可以自行修改
string fileName = DateTime.Now.ToString("yyyyMMddHHmm") + ".htm";
str = str.Replace("$content$", txtContent.Text);//替换content
//生成静态文件
try
{
sw = new StreamWriter(Server.MapPath("~/") + fileName, false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sw.Close();
Response.Write("<a href=" + fileName + " mce_href=" + fileName + " target=_blank>" + fileName + "</a>已经生成!");
}
}