Question

We're using Piranha CMS with the following setting:

<prefixlessPermalinks value="true" />

However this breaks individual posts urls generated using the Permalink helper e.g.

@UI.Permalink(post.PermalinkId)

With prefixlessPermalinks set to False this would normally be the url that is generated: /home/1st-test-blog-entry

With prefixlessPermalinks set to True the url generated becomes: /1st-test-blog-entry (the "home" has been removed as it's prefixless)

Following a prefixless url generates the following exception:

System.Web.HttpException: Cannot use a leading .. to exit above the top directory.

Any ideas how to circumnavigate this issue?

Attempted workarounds:

I manually prefix "/post" to the permalink generated then I added the following route mapping which catches the request:

routes.MapRoute(
    name: "Post",
    url: "post/{permalink}",
    defaults: new { controller = "Post", action = "Index", permalink = UrlParameter.Optional },
    namespaces: new[] { "Maps.Portal.Controllers" }
).DataTokens["UseNamespaceFallback"] = false;

The following controller catches the request:

public ActionResult Index(string permalink)
{
    var model = GetModel(permalink);

    return View(model.GetView(), model);
}

But fails as the readonly SinglePostController.CurrentPermalink property isn't being populated and so causes Piranha CMS to throw an exception. It may be interesting to note that this controller fires correctly when the draft version of the post is being viewed as the CurrentPermalink is being populated by the CMS.

Was it helpful?

Solution

After experimentation I can confirm that the issue isn't with Piranha CMS, but with the MVC shared layout. Still trying to track it down, but stripping out everything apart from the CMS content allows the post page to be shown.

Update:

I finally tracked it down to multiple uses of @Url.Content(url). Very bizarre as all seem to be valid urls e.g. @Url.Content("~/Content/images/ios/57x57iOS.png"). Once these were all removed then the page would render correctly!?

Discovery:

This issue turned out to be a development environment only issue for me...

Running the site in Visual Studio Development Server from VS2012 results in this error, but once the web application was deployed to IIS8 the issue disappeared.

OTHER TIPS

I can't reproduce your error with either MVC or Web Pages, in fact we use prefixless permalinks in almost all live installations I've deployed. I started up the MVC template, installed a fresh database and added a post with your specified title/permalink and it shows up without issues with prefixless permalinks.

enter image description here

How have you set up your installation?

Regards

/Håkan

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top