Storing links to internal content pages in ASP.NET MVC

Posted by mare on Stack Overflow See other posts from Stack Overflow or by mare
Published on 2010-04-23T15:21:37Z Indexed on 2010/04/23 15:23 UTC
Read the original article Hit count: 348

Filed under:
|

I'm using a route like this

        routes.MapRoute(
            "PageBySlug",
            RouteType.Regular,
            "{slug}",
            new {controller = "Page", action = "Display", slug = "Default"}, null
            );

to map request to ~/Some-Page-Slug to ~/Page/Display/Some-Page-Slug.

When adding content, user can choose to link to existing pages to create references and I then store those links in this format in the datastore: "/Some-Page-Slug".

When I run the app in Cassini and pull the link out from datastore and attach it to A tag it looks like this http://localhost:93229/Some-Page-Slug and this link works.

But when running the application in virtual directory under some website in IIS, the attached link generates this URL http://localhost/Some-Page-Slug, when it should be http://localhost/virtualdir/Some-Page-Slug.

Of course, this generates 404 error.

How can I solve this to be universally useful and working under all circumstances? Should I store it differently in the database or should I transform it into correct form in my Views at runtime and how to do that?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about routing