• url重写的方法


    现在的网站一般都有url重写的方法,让人看上去像静态页面一样,具体 怎么实现的,请看以下代码。

    做个新闻系统,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)
            {

    读取新闻信息

            }

  • 相关阅读:
    IEEE 754 浮点数的表示方法
    .NET Core 3.0及以上的EFCore连接MySql
    一些常见错误/技巧/结论总结
    2-sat学习笔记
    动态DP学习笔记
    动态规划优化算法——wqs二分 and 折线优化
    扩展莫队小总结(二) (回滚莫队/二次离线莫队)
    CF1504X Codeforces Round #712
    CF1500D Tiles for Bathroom (递推+大讨论)
    CF1486X Codeforces Round #703
  • 原文地址:https://www.cnblogs.com/hsapphire/p/1721742.html
Copyright © 2020-2023  润新知