【问题标题】:UrlRewriter.NET - simple rewrite rule, but how?UrlRewriter.NET - 简单的重写规则,但如何?
【发布时间】:2012-08-11 19:10:09
【问题描述】:

我刚刚从 Urlrewriter.net 安装了示例,但我似乎无法弄清楚 完成我的问题的规则。

很简单:

如果用户被导航到这个页面:

http://localhost/UrlRewriteTest/Default.aspx?PageID=33

网址应如下所示:

http://localhost/UrlRewriteTest/33

或许

http://localhost/UrlRewriteTest/33.aspx

我做错了什么?这是我的 web.config:

<?xml version="1.0"?>
<configuration> 
  <configSections>
    <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"/>
  </configSections>
    <system.web>
    <httpModules>
      <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
    </httpModules>
    <compilation targetFramework="4.0"/>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
  </system.web> 
  <rewriter>
    <rewrite url="~/(.+)" to="~/Default.aspx?PageID=$1"/> 
  </rewriter>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
            <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
        </modules>
        <validation validateIntegratedModeConfiguration="false" />
    </system.webServer>
</configuration>

这是第一步。更理想的 PageID 应该传递给数据库 并返回页面名称而不是 ID,并且 URL 应该最终看起来 像这样:

http://localhost/UrlRewriteTest/thename/

最好的问候。

【问题讨论】:

    标签: asp.net url-rewriting url-rewrite-module urlrewriter.net


    【解决方案1】:

    您可以阅读 Scott Guthrie 关于 Url Rewriting @http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx 的文章。

    【讨论】:

    • 嗨 - 感谢您的链接。我已经阅读了这篇文章,并且解释得很好,但我似乎无法解决我的具体问题。我对 URL 重写完全不熟悉,所以我感谢我还没有看到光明..
    • 您好,您是否尝试过下载第二个示例的source code 并根据您的特定需求进行调整?
    • 嗨,我真的试过了,这里有一个非常简单的例子,它真的应该工作。你能看出我做错了什么或应用哪种魔法吗? dl.dropbox.com/u/17202645/UrlRewrite_HttpModule1_SimpleTest.zip
    • 也许我的问题是我试图将带有查询字符串的 URL 转换为漂亮的 URL 而不是反转?我应该在这里实现 som Global.asax 功能吗?
    • urlrewriter.net 网站无论如何都消失了,项目被放弃了?所以那篇文章也没什么用。对于找到此内容的人,请尝试github.com/Bikeman868/UrlRewrite.Net,截至本评论日期仍在维护。
    猜你喜欢
    • 1970-01-01
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-25
    • 2011-11-09
    • 2014-02-04
    相关资源
    最近更新 更多