2
我剛剛安裝了Urlrewriter.net的示例,但似乎無法找出完成我的問題的規則 。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/
最好的問候。
嗨 - 感謝您的鏈接。我已經閱讀過這篇文章,並且已經很好地解釋了這一點,但我似乎無法解決我的具體問題。我完全陌生的URL重寫,所以我感謝我還沒有看到光.. – micknt 2012-08-15 13:49:52
嗨,你有沒有嘗試下載[源代碼](http://www.scottgu.com/blogposts/urlrewrite/UrlRewrite_HttpModule1 .zip)的第二個樣本,並根據您的具體需求進行調整? – Esteban 2012-08-15 13:54:26
嗨,我真的嘗試過,這是一個非常簡單的例子,它應該可以工作。你可以說我做錯了什麼或者應用哪種魔法? https://dl.dropbox.com/u/17202645/UrlRewrite_HttpModule1_SimpleTest.zip – micknt 2012-08-16 08:55:01