I’d like to add a trailing slash to any url’s that match a valid route but do not currently end in a slash, i.e. http://www.example.com/url
After a url is matched to a valid route I would like to 301 redirect to the same url but add the trailing slash i.e. http://www.example.com/url/
I’ve spent some time looking into it but I can’t seem to figure it out.
I believe routes are matched in the PostResolveRequestCache event, but I don’t know how to access the routedata during or after that event to see if a valid route was matched. If I can confirm that a valid route was matched then I can check the url to make sure it ends in a slash.
I hope that’s clear enough, let me know if you need more info.
I assume you are trying to eliminate duplicate content for SEO purposes.
Scott Hanselman says you can do this with the IIS7 Rewrite module (are you running IIS7?) His post at http://www.hanselman.com/blog/ASPNETMVCAndTheNewIIS7RewriteModule.aspx describes the process.