2

I have just installed the sample from Urlrewriter.net, but I can't seem to figure out the rule for accomplishing my problem.

Very simple:

If the user is navigated to this page:

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

The Url should look like:

http://localhost/UrlRewriteTest/33

or maybe

http://localhost/UrlRewriteTest/33.aspx

What am I doing wrong? Here is my 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>

That is the first step. More ideally PageID should be passed to a database and return the pagename instead of an ID, and the URL should end up looking like this:

http://localhost/UrlRewriteTest/thename/

Best regards.

micknt
  • 297
  • 1
  • 8
  • 23

1 Answers1

1

You can read Scott Guthrie's article about Url Rewriting @ http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx.

Esteban
  • 3,108
  • 3
  • 32
  • 51
  • Hi - thanks for the link. I have already been through the article, and it is pretty well-explained, but I can't seem to get my specific problem solved. I'm totally new to URL-rewriting so I thank I haven't seen the light yet.. – micknt Aug 15 '12 at 13:49
  • Hi, have you tried downloading the [source code](http://www.scottgu.com/blogposts/urlrewrite/UrlRewrite_HttpModule1.zip) of the second sample and adjusting it to your specific needs? – Esteban Aug 15 '12 at 13:54
  • Hi, I have really tried and here is a very simple example which really should work. Can you se what I'm doing wrong or which magic to apply? https://dl.dropbox.com/u/17202645/UrlRewrite_HttpModule1_SimpleTest.zip – micknt Aug 16 '12 at 08:55
  • Maybe my problem is that I'm trying to convert a URL with a querystring into a nice looking URL and not reverse? Should I implement som Global.asax functionality here? – micknt Aug 16 '12 at 09:59
  • He didn't come here for something google would have given him. Don't post answers as 3rd party links. – B. Shea May 30 '17 at 20:54
  • 1
    urlrewriter.net website is gone anyway and project is abandoned? so that article is also of very little use. For ppl who find this, try https://github.com/Bikeman868/UrlRewrite.Net which is still maintained as of this comment date. – B. Shea May 30 '17 at 20:58