1

I know that you can create routes in asp.net web forms, but how do I go about creating one that handles all my pages like mydomain.com/aboutus?

I have heard about custom iroute handlers but can someone actually show me an example?

Can someone please send me an example in C# of how I would go about this? I do have a file called page.aspx that will process all the requests for the CMS. I think it's a root handler I need.

Rob
  • 45,296
  • 24
  • 122
  • 150
c-sharp-and-swiftui-devni
  • 3,743
  • 4
  • 39
  • 100
  • Rob, being the one that "answered" your question, I've taken this approach in doing my own rapid CMS product. If you want to take a look and ask me about it, it may help you as you are building your own. Its in my profile detail. Cheers. – King Friday Dec 16 '11 at 17:10

2 Answers2

0

One way to handle this would be through re-writes - much the same as Wordpress, ExpressionEngine and many other CMS's.

You could re-write the requests to the page.aspx file with the requested 'page' being a parameter and process as required...

mod_rewrite equivalent for IIS 7.0 has a lot of info on re-write modules for IIS and then you could research any number of open source solutions that use this method for 'pretty' or 'seo friendly' URL's

Community
  • 1
  • 1
Dave Kirk
  • 511
  • 4
  • 10
  • can you not achieve this with asp.net routing ~? – c-sharp-and-swiftui-devni Dec 08 '11 at 11:03
  • you could, a quick search bought up http://stackoverflow.com/questions/379558/mvc-net-routing#379823 which seems to go into detail about a custom IRouteHandler. I've never attempted this - I am new to ASP.NET - which is why I didn't suggest it as an answer :-) – Dave Kirk Dec 08 '11 at 11:20
0

URL Rewrite in IIS 7 and IIS 7.5 does this very nicely. You need to first install URL Rewrite into IIS via the Web Platform Installer. After that, you would place this in your web.config.

<system.webServer>
    <rewrite>
        <rules>
            <rule name="admin" stopprocessing="true">
                <match url="^admin/(.+)$" />
                <action type="Rewrite" url="/admin/{R:1}.aspx" />
            </rule>
            <rule name="pagehandler">
                <match url="^(.*)$" />
                <action type="Rewrite" url="/pagehandler.aspx?page={R:1}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

You can place more pages that are not dynamically changing via the CMS above the "page handler" rule. The /pagehandler.aspx would take the page ID has the parameter and dynamically serve its contents. That is your part to work out.

King Friday
  • 25,132
  • 12
  • 90
  • 84