您的位置:首页 > 其它

URL重写步骤 【有用】

2010-02-05 11:10 106 查看

做个新闻系统,URL重写每个新闻

1. Web.config 的配置

<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
</httpModules>

<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/(\d+)\.aspx</LookFor>
<SendTo>~/Detail.aspx?ID=$1</SendTo>
</RewriterRule>

</Rules>
</RewriterConfig>

2. 创建页面文件

<asp:Repeater ID="rptbulletin" runat="server">
<ItemTemplate>
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td height="20">
<a class="Other" href='Log/<%# Eval("ID")%>.aspx' target="_blank" title='<%#Eval("Title") %>'>·<%# (Eval("Title") %></a>
</td>
</tr>
</tbody>
</table>
</ItemTemplate>
</asp:Repeater>

建立 BulletinDetails.aspx

PageLoad 方法中

string id = Request.QueryString["ID"];
if (id != null)
{

读取新闻信息

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: