关于生成静态页面的问题
我是用模板生成html的,但是有个问题 在模板页 我想去调用 <iframe frameBorder= "0 " scrolling= 'no ' src= "../inc/infoLeft.aspx "> </iframe> 但是infoLeft.aspx里的服务器控件都不用读出来 我想问一下 怎么样才能调用aspx里的内容
------解决方案--------------------WebRequest request = WebRequest.Create( HttpContext.Current.Server.MapPath( "Default.aspx ") );
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader( stream,System.Text.Encoding.GetEncoding( "gb2312 ") );
string str = reader.ReadToEnd();
StreamWriter writer = new StreamWriter( HttpContext.Current.Server.MapPath( "Index.htm "),false,System.Text.Encoding.GetEncoding( "gb2312 ") );
writer.Write( str );
------解决方案--------------------不要添加就不会读出来。
另外,visiable=false也不会读出来。
------解决方案--------------------估计是路径错误了
你直接打../inc/infoLeft.aspx看是什么效果
------解决方案--------------------一般都是定义模板页,然后替换字符来生产html的
------解决方案-------------------- <%@ Import Namespace= "System.IO " %>
<%@ Import Namespace= "System.Text " %>
<script runat= "server " language= "vb ">
'该过程用来生成HTML网页
Sub Enter_Click(Sender As System.Object, E As System.EventArgs)
'下面首先读取模板文件,将其中的全部代码保存到一个字符串中
Dim strTemplate As String
Dim sr As New StreamReader(Server.MapPath( "template.htm "), Encoding.GetEncoding( "gb2312 "))
strTemplate=sr.ReadToEnd()
sr.Close()
'下面利用客户输入的内容替换模板中的相应字符串
strTemplate=strTemplate.Replace( "$title$ ",txtTitle.Text)
strTemplate=strTemplate.Replace( "$body$ ",txtBody.Text)
strTemplate=strTemplate.Replace( "$SubmitDate$ ",Now())
'下面建立一个StreamWriter对象,生成HTML文件
Dim sw As New StreamWriter(Server.MapPath(GetFileName()), False, Encoding.GetEncoding( "gb2312 "))
sw.Write(strTemplate)
sw.Close()
'下面给出一个浏览超链接
message.Text = " <a href= ' " & GetFileName() & " ' target= '_blank '> 请查看生成的文件 </a> "
End Sub
'该函数用来返回由当前时间组成的文件名称
Function GetFileName()
GetFileName = Now().ToString.Replace( "- ", " ").Replace( ": ", " ").Replace( " ", " ")
GetFileName = GetFileName & ".htm "
End Function
</script>
<HTML>
<body>
<h3 align= "center "> 利用模板生成HTML文件 </h3>
<form runat= "server ">
<table width= "80% " align= "center ">
<tr>
<td width= "30% " align= "right "> 标题 </td>
<td> <asp:Textbox id= "txtTitle " columns= "50 " runat= "server "/> </td>
</tr>
<tr>
<td width= "30% " align= "right "> 内容 </td>
<td> <asp:Textbox id= "txtBody " TextMode= "MultiLine " rows= "8 " columns= "40 " runat= "server "/> </td>
</tr>
<tr>
<td colspan= "2 " align= "center "> <asp:Button id= "Enter " Text= "确定