How do I get URL rewriting?

Topics: Developer Forum
Sep 26, 2008 at 4:38 PM
Edited Sep 26, 2008 at 4:44 PM
Warning: I'm completly new to N2.

I am trying to get N2 working with an existing website, I followed the instructions on the website and added this code to my preexisting Default.aspx page:

<asp:Literal ID="TextLiteral" Text="<%$ CurrentPage: Text %>" runat="server" />

I added "Hello Default!" to the "Start Page" node, brought up the site (http://localhost/default.aspx) and saw the content. Great.

Next I tried to create a "hello-world" page within N2. I selected the root node, hit the "Create new item below selected item" button, selected the only item type available, set the title to "hello world", the URL Name to "hello-world", and the text to (you guessed it) "Hello World!".

Finally, I called up the site by going to http://localhost/hello-world. I got a 404 error. I then tried going to http://localhost/hello-world.aspx but again got a 404 error.

Can someone tell me what I'm missing to get this working?

Thanks!

-James
Sep 26, 2008 at 4:42 PM
Sorry about the formatting! There doesn't seem to be anything I can do to fix it :(
Coordinator
Sep 27, 2008 at 1:04 PM
What you preview your hello-world page from within the edit interface can you see it? What url is it assigned? Is it something like "/path/to/my/page.aspx?page=3"?

Maybe N2 doesn't recognize your "hello default" as the start page for the site.

What does it say in your web? <n2><host rootID="1" startPageID="1" should point to the hello default page.
Sep 29, 2008 at 2:24 PM
> What you preview your hello-world page from within the edit interface can you see it?

Yes I can.

> What url is it assigned? Is it something like "/path/to/my/page.aspx?page=3"?

Yes: /default.aspx?page=5

> What does it say in your web? <n2><host rootID="1" startPageID="1" should point to the hello default page.

It says: <host rootID="1" startPageID="2" />

I still do not understand how I can get /hello-world to work. Any suggestions?
Sep 29, 2008 at 3:45 PM
does any of these work:$0$0$0http://localhost/default.aspx?page=5$0$0http://localhost/hello-world.aspx$0$0$0$0What is the Name of the Hello World page (WithEditableName)?$0$0
Sep 29, 2008 at 3:56 PM
Edited Sep 29, 2008 at 3:58 PM
> http://localhost/default.aspx?page=5

Yes, this works.

> http://localhost/hello-world.aspx

This does not work. I get a 404 error.

What is the Name of the Hello World page (WithEditableName)?

It is "hello-world".

Thank you for your help. Hopefully I can get this working soon!

-James
Coordinator
Sep 29, 2008 at 4:22 PM
Just to make sure. The id of your start page (the page above "hello-world") is 2, same as in web.config?
Sep 29, 2008 at 4:37 PM
> The id of your start page (the page above "hello-world") is 2, same as in web.config?

Yes. My start page ID is 2 and the Web.Config has startPageID="2" as part of the <host> tag.
Sep 29, 2008 at 5:49 PM
Can you post the contents of the <n2><host> sub-element in web.config?
Sep 29, 2008 at 6:28 PM
  <n2>
<host rootID="1" startPageID="2" />
<engine>
<assemblies>
<add assembly="N2"/>
<add assembly="N2.Edit"/>
<add assembly="N2.Security"/>
</assemblies>
</engine>
<database connectionStringName="N2CMS" flavour="SqlServer2005"
caching="true" cacheProviderClass="NHibernate.Caches.SysCache2.SysCacheProvider, NHibernate.Caches.SysCache2" />
<edit>
<installer checkInstallationStatus="true" />
</edit>
</n2>
Coordinator
Sep 29, 2008 at 6:31 PM
Also writing out the start page's child urls could give some hints:

add to default.aspx:
<% foreach(ContentItem item in CurrentPage.Children) {%>
<li><%= item.Title %>: <%= N2.Context.UrlParser.BuildUrl(item) %></li>
<%}%>
Sep 29, 2008 at 7:30 PM
Hi Libardo,

This is the output:
  • Start page: /
  • Simple Content Test: /default.aspx?page=5
  • Wizard settings: /default.aspx?page=1&item=10
Coordinator
Sep 29, 2008 at 8:49 PM
Okay, just drag "Simple Content Test" to the "Start page" node. That should do it. The idea is that only nodes that are below the start page (/) can be accessed through a friendly URL. The others are still accessible for convenience.

We should probably make this obvious in the interface. Maybe some kind of warning sign next to the name box.
Sep 29, 2008 at 9:28 PM
> Okay, just drag "Simple Content Test" to the "Start page" node.

That did it! Thank you so much, I am very excited to have found this framework!