欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【ASP.NET静态页生成方法】,下面是详细的讲解!
ASP.NET静态页生成方法
/// <summary>/// 解析模板的html中匹配的标签,进行替换(暂时只能用于没有分页的页面)
/// </summary>
/// <param name="html">HTML</param>
/// <returns>返回替换后的HTML</returns>
public static string ReturnHtml(string html)
{
string newhtml=html;
newhtml=newhtml.Replace("<#Title#>", "这个是标题替换");//替换标题
//newhtml=newhtml.Replace("<#Content#>", "这个是内容替换");//替换标题
newhtml=CreateList(newhtml);
return newhtml;
}
/// <summary>
/// 读取HTML文件
/// </summary>
/// <param name="temp">html文件的相对路径</param>
/// <returns>返回html</returns>
public static string ReadHtmlFile(string temp)
{
StreamReader sr=null;
string str="";
try
{
sr=new StreamReader(HttpContext.Current.Server.MapPath(temp), code);
str=sr.ReadToEnd(); // 读取文件
}
catch (Exception exp)
{
HttpContext.Current.Response.Write(exp.Message);
HttpContext.Current.Response.End();
}
finally
{
sr.Dispose();
sr.Close();
}
return str;
}
/// <summary>
/// 生成html文件
/// </summary>
/// <param name="filmname">文件名(带相对路径路径,如:../a.html)</param>
/// <param name="html">html内容(整个)</param>
public static void writeHtml(string filmname, string html)
{
System.Text.Encoding code=System.Text.Encoding.GetEncoding("utf-8");
string htmlfilename=HttpContext.Current.Server.MapPath(filmname);
string str=html;
StreamWriter sw=null;
// 写文件
try
{
sw=new StreamWriter(htmlfilename, false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
}
关于ASP.NET静态页生成方法的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 【asp】asp.net url重写浅谈-net-url重写
- 【DataSet】DataSet、DataTable、DataRow区别详解
- 【asp】asp.net 动态添加多个用户控件-net-动态添
- 【ASP】ASP.NET中内嵌页面代码的一个问题-NET-内
- 【As】Asp.net中的页面乱码的问题-sp--pn-ne-et
- 【增加记录】asp.net中获取新增加记录的ID Access
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【Asp】Asp.net 页面调用javascript变量的值-net-
- 【ASP】ASP.NET 5升级后如何删除旧版本的DNX-NET5
- 【404页面】ASP.NET设置404页面返回302HTTP状态码
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
