编程开发 > ASP > 文章内容

利用ASP.NET3.5的路由功能创建搜索引擎友好的URL(5)

2010-10-20编辑:dan

5、按照自定义路由处理程序中定义的实际处理程序,分别添加ArticleShow.aspx、ArticleAdd.aspx、 ArticleEdit.aspx、ArticleComment.aspx、ArticlePrint.aspx和ArticleList.aspx等真正的处理程序。 作为例子,这里列出ArticleShow.aspx、ArticleAdd.aspx和ArticleList.aspx的源代码分别如下:

ArticleAdd.aspx

 


<%@ Page Language="C#" ValidateRequest="false" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<mce:script runat="server"><!--
protected void Button1_Click(object sender, EventArgs e)
{
String ConnectionString = "Data Source=(local);Initial Catalog=ArticleDev;User ID=sa;Password=sa";
SqlConnection cn = new SqlConnection(ConnectionString);
cn.Open();
String sql = "Insert Into Article(Title,Content) Values(@Title,@Content)";
SqlCommand cmd = new SqlCommand(sql, cn);
cmd.Parameters.AddWithValue("@Title", TextBox1.Text);
cmd.Parameters.AddWithValue("@Content", TextBox2.Text);
int ret = cmd.ExecuteNonQuery();
if (ret == 1)
{
Label1.Text = "添加成功。";
}
else
{
Label1.Text = "添加失败。";
}
cn.Dispose();
}
// --></mce:script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>文章标题:<asp:TextBox ID="TextBox1" runat="server" Width="767px"></asp:TextBox></div>
<div>文章内容:<br />
<asp:TextBox ID="TextBox2" runat="server" Width="845px" Height="319px" TextMode="MultiLine">
</asp:TextBox></div>
<asp:Button ID="Button1" runat="server" Text="添加文章" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</form>
</body>
</html>

 

利用ASP.NET3.5的路由功能创建搜索引擎友好的URL(4)

热点推荐

登录注册
触屏版电脑版网站地图