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();
    
     
	
	
    
    
	相关文档:
        
    
    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=¼&fra ......
	
    
        
    
    学习ASP.NET中的Application、Session、Cookie
1.Application建立的变量,在系统内部任何地方都可以访问,通常网站地访问统计可能会用的较多。如果要用到Application首先在VS2005中建立一个global.asa文件。例如我们要写一个网站访问数量的统计的话,在global.asa中先声明变量iCount。如下所示:
     ......
	
    
        
    
    
方法
数据量
生命期
作用域
位置
Application
任意大小
整个应用程序
所有用户
服务端
Cache
任意大小
根据需要设定
所有用户
服务端
Cookie
简单数据
根据需要设定
单个用户
客户端
Session
简单数据
用户活动时间+延迟时间(20分钟)
单个用户
服务端
Web.Config
极少改变简单数据
直到改变配 ......
	
    
        
    
    +++ 修改Global.asax文件:
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e) 
{
  Application["count"] = 0;
}
void Application_End(object sender, EventArgs e) 
{  }
void Application_Error(object sender, EventArgs ......
	
    
        
    
    参考 http://topic.csdn.net/t/20040510/19/3051316.html
      开始 
      运行 
      dcomcnfg 
      组件服务一项中选择Dcom配置,找到Microsoft   excel应用程序,察看属性 
      安全选项卡中,启动权限和访问权 ......