国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net 生成靜態(tài)頁筆記

2024-07-10 12:41:51
字體:
供稿:網(wǎng)友
1.使用serever.Excute
代碼如下:
StreamWriter sw = new StreamWriter(Server.MapPath("html/Login.html"), false);
Server.Execute("ShowColumn.aspx?id=1&page=2", sw);
sw.Close();

2.替換字符

url重寫
1.定義重寫規(guī)則
urls.xml 變成urls.config
代碼如下:
<?xml version="1.0" encoding="utf-8" ?>
<Urls>
<rewrite name="ShowArticle" pattern="article-(/d+).html" path ="article-{0}.html" page="showarticle.aspx" query="id=$1"></rewrite>
<rewrite name="ShowList" pattern="list-(/d+).html" path ="list-{0}.html" page="showlist.aspx" query="id=$1"></rewrite>
</Urls>

2.創(chuàng)建一個簡單的實體urls類
3.urls類 獲取urls.config文件中的所有url
4.httpmodule類處理 請求的地址
5.在web.config httpmodule節(jié)點添加

asp.net生成靜態(tài)頁的兩種方法

Default.aspx頁面:
代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication6._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Asp.net生成靜態(tài)頁的兩個例子</title>
</head>
<body>
<form id="form1" runat="server">
<div>
標(biāo)題:<asp:TextBox ID="txtTitle" runat="server" Width="352px"></asp:TextBox><br />
內(nèi)容:<asp:TextBox ID="txtContent" runat="server" Height="179px" TextMode="MultiLine"
Width="350px"></asp:TextBox><br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="根據(jù)模板生成" /><br />
<br />
<br />
Url地址:<asp:TextBox ID="txtUrl" runat="server" ToolTip="請確認Url地址的存在" Width="359px"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button2" runat="server" Text="根據(jù)Url地址生成" OnClick="Button2_Click" /></div>
</form>
</body>
</html>

Default.aspx.cs
代碼如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Text;
using System.IO;
namespace WebApplication6
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//源碼是替換掉模板中的特征字符
string mbPath = Server.MapPath("template.htm");
Encoding code = Encoding.GetEncoding("gb2312");
StreamReader sr = null;
StreamWriter sw = null;
string str = null;
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 崇义县| 桦甸市| 南澳县| 双城市| 崇明县| 启东市| 龙陵县| 海林市| 阿尔山市| 芦溪县| 泸州市| 来宾市| 巴林右旗| 黄大仙区| 东方市| 新蔡县| 雷州市| 轮台县| 阳朔县| 图们市| 庆元县| 双鸭山市| 永定县| 阳高县| 格尔木市| 永春县| 抚宁县| 香港 | 鹤山市| 安多县| 贺兰县| 永寿县| 昭苏县| 砀山县| 镇雄县| 宝坻区| 如东县| 灵山县| 遂平县| 鄂尔多斯市| 通城县|