易截截图软件、单文件、免安装、纯绿色、仅160KB

asp.net生成静态页的方法





1、直接将页面内容存在变量中后输出: 
 StringBuilder IndexContentResult= new StringBuilder(); //存放输出页面的HTML 
 IndexContentResult.Append("<html>\n"); 
 IndexContentResult.Append("  <head>\n");
 IndexContentResult.Append("    <title>title</title> \n");
 IndexContentResult.Append("  </head>\n");
 IndexContentResult.Append("  <body>\n");
 ...
 IndexContentResult.Append("  <body>\n");
 IndexContentResult.Append("</html>\n");
 string tempfile = Server.MapPath("~");
 tempfile = tempfile + "index.htm";
 System.IO.StreamWriter sr = new System.IO.StreamWriter(tempfile, false, System.Text.Encoding.Default);
 sr.Write(IndexContentResult.ToString());
 sr.Close();
2、用模板替换:
 template.htm  //模板文件
 <html>
 <head>
 <title>$title$</title>
 </head>
 <body>
 $body$
 </body>
 </html>
 
 .cs代码文件
 string title = "生成的网页标题";
 string body = "生成的网页内容"; 
 string filename = Server.MapPath("~/") + "frame_a/index.htm"; 
 System.IO.StreamReader srm = new System.IO.StreamReader(filename,System.Text.Encoding.Default);    
 string mb = srm.ReadToEnd();
 srm.Close();
 string tempfile = Server.MapPath("~/") + "index.htm";
 StreamWriter sr = new System.IO.StreamWriter(tempfile, false, System.Text.Encoding.Default);
 mb = mb.Replace("$title$", title);
 mb = mb.Replace("$body$", body);
 sr.Write(mb);
 sr.Close();


相关文档:

设置自定义ASP.NET服务器控件TagPrefix的几种方法

这两天看《道不远人-----深入解析ASP.NET2.0控件开发》这本书,看完第二章内容后,想总结下“设置自定义ASP.NET服务器控件TagPrefix的几种方法”,以便以后查阅,以下面code编写的控件为例,由于重点不是控件编写,所以写了个非常简单的控件,姑且叫它EmailInput
Code
 1using System;
 2using ......

Asp.net页面传值的几种方式

一、使用QueryString参数
QueryString将传递的值显示在浏览器的地址栏中,是一种非常简单也使用比较多的传值方式。
如果传递一个或多个安全性要求不高或是结构简单的数值时,可以使用这个方法
/// <summary>
/// 使用QueryString变量
/// </summary>
/// <param name="param1"></param>
/// ......

asp.net 获取当前URL的正确方法

HttpContext.Current.Request.Url.ToString() 并不可靠。
如果当前URL为
http://localhost/search.aspx?user=http://csharp.xdowns.com&tag=%BC%BC%CA%F5
通过HttpContext.Current.Request.Url.ToString()获取到的却是
http://localhost/search.aspxuser=http://csharp.xdowns.com&tag=&frac14;&fra ......

学习ASP.NET中的Application、Session、Cookie

学习ASP.NET中的Application、Session、Cookie
1.Application建立的变量,在系统内部任何地方都可以访问,通常网站地访问统计可能会用的较多。如果要用到Application首先在VS2005中建立一个global.asa文件。例如我们要写一个网站访问数量的统计的话,在global.asa中先声明变量iCount。如下所示:
     ......

ASP.NET页面传值_第二篇_查询字符串

例一:
+++ 第一个页面
++ 页面代码如下:
<div>
 <a href="QueryString04.aspx?blog=DoooooNetooooot.blog.tianya.cn&qq=516535763">超链接传值示例</a>
</div>
++ 后台代码如下:
(略)
+++ 第二个页面
++ 页面代码如下:
(略)
++ 后台代码如下:
protected void Page_Load( ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号