Changing the URL structure
I wanted the following URL structure in my website
www.mysite.com/product/myproductname/whatsnew
but the default url mapping in MonoRail would translate this as
www.mysite.com/[controller]/[action]/[id]
So it would expect to find this
public class ProductController
{
public void MyProductName(string id)
{
}
}
whereas what I actually want is
public class ProductController
{
public void WhatsNew(string productName)
{
}
}
As this is at the top of the list it will have the highest priority. If the URL matches /product it will remap the url
From:
www.mysite.com/product/myproductname/whatsnew
To:
www.mysite.com/product/whatsnew.rails?productname=MyProductName
without the user ever seeing it :-)
www.mysite.com/product/myproductname/whatsnew
but the default url mapping in MonoRail would translate this as
www.mysite.com/[controller]/[action]/[id]
So it would expect to find this
public class ProductController
{
public void MyProductName(string id)
{
}
}
whereas what I actually want is
public class ProductController
{
public void WhatsNew(string productName)
{
}
}
- Open Web.Config
- Locate the monorail node
- Locate the routing child node
- Now add a new <rule> to the top of the list:
<rule>
<pattern>/(product)/(\w+)/(\w+)</pattern>
<replace><![CDATA[ /product/$3.rails?productName=$2]]></replace>
</rule>
As this is at the top of the list it will have the highest priority. If the URL matches /product it will remap the url
From:
www.mysite.com/product/myproductname/whatsnew
To:
www.mysite.com/product/whatsnew.rails?productname=MyProductName
without the user ever seeing it :-)
Comments