ASP.NET-生成静态页面后台怎么调用动的数据

ASP.NET-生成静态页面后台怎么调用动的数据

晚风撩人 发布于 2016-11-02 字数 3030 浏览 1295 回复 3

以下是.我用动态生成的静态页面代码.
摸版html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<HEAD>
<title>ShowArticle</title>
<body>
ShowArticle
<br>
biaoti<br>
contents
</body>
</HTML>
后台代码
public static bool WriteFile(Compas pc)
{
string path = HttpContext.Current.Server.MapPath("~/news/");
Encoding code = Encoding.GetEncoding("gb2312");
// 读取模板文件
string temp = HttpContext.Current.Server.MapPath("~/news/text.htm");
StreamReader sr = null;
StreamWriter sw = null;
string str = "";
try
{
sr = new StreamReader(temp, code);
// 读取文件
str = sr.ReadToEnd();
}
catch (Exception exp)
{
HttpContext.Current.Response.Write(exp.Message);
HttpContext.Current.Response.End();
sr.Close();
}
//用当前时间做为名称如20100324161954.html
string htmlfilename = pc.AddTime.ToString();
// 替换内容
// 这时,模板文件已经读入到名称为str的变量中了
str = str.Replace("ShowArticle", pc.Compasstitle); //模板页中的ShowArticle
str = str.Replace("biaoti", pc.Compasstitle);
str = str.Replace("contents", pc.Compasscotent);
str = str.Replace("author", pc.Upuser);
// 写文件
try
{
sw = new StreamWriter(path + htmlfilename, false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
return true;
}

Compas pc = new Compas();
pc.Compasstitle = txtName.Text.Trim();
pc.Compasscotent = FCKeditor1.Value.ToString();
pc.UpMove = lbwork.Text.ToString();
pc.UpTime = DateTime.Now.ToString();
pc.AddTime = DateTime.Now.ToString("yyyyMMddHHmmss")+ ".html";
pc.Upuser = lbOperator.Text.ToString();
int planeReslut = CompasManager.Instance.AddCompas(pc);
if (planeReslut > 0)
{
if (WriteFile(pc))
{
Response.Write("添加成功");
}
else
{
Response.Write("生成HTML出错!");
}

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瑾兮 2017-09-07 3 楼

后台代码

public static bool WriteFile(Compas pc)
{
string path = HttpContext.Current.Server.MapPath("~/news/");
Encoding code = Encoding.GetEncoding("gb2312");
// 读取模板文件
string temp = HttpContext.Current.Server.MapPath("~/news/text.htm");
StreamReader sr = null;
StreamWriter sw = null;
string str = "";
try
{
sr = new StreamReader(temp, code);
// 读取文件
str = sr.ReadToEnd();
}
catch (Exception exp)
{
HttpContext.Current.Response.Write(exp.Message);
HttpContext.Current.Response.End();
sr.Close();
}
//用当前时间做为名称如20100324161954.html
string htmlfilename = pc.AddTime.ToString();
// 替换内容
// 这时,模板文件已经读入到名称为str的变量中了
str = str.Replace("ShowArticle", pc.Compasstitle); //模板页中的ShowArticle
str = str.Replace("biaoti", pc.Compasstitle);
str = str.Replace("contents", pc.Compasscotent);
str = str.Replace("author", pc.Upuser);
// 写文件
try
{
sw = new StreamWriter(path + htmlfilename, false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
return true;
}

Compas pc = new Compas();
pc.Compasstitle = txtName.Text.Trim();
pc.Compasscotent = FCKeditor1.Value.ToString();
pc.UpMove = lbwork.Text.ToString();
pc.UpTime = DateTime.Now.ToString();
pc.AddTime = DateTime.Now.ToString("yyyyMMddHHmmss")+ ".html";
pc.Upuser = lbOperator.Text.ToString();
int planeReslut = CompasManager.Instance.AddCompas(pc);
if (planeReslut > 0)
{
if (WriteFile(pc))
{
Response.Write("添加成功");
}
else
{
Response.Write("生成HTML出错!");
}

夜无邪 2017-06-22 2 楼

后台想获取前台静态页的数据,需要在前台页面生成form标签,再用post或者get方法提交数据给后台

想挽留 2016-11-26 1 楼

请学习ajax相关内容