OrchardCore: Fix modules that don't correctly use PathBase-relative root paths

Many modules - like the setup module - reference CSS and JS files using root-relative paths. E.g:

<link type="text/css" rel="stylesheet" href="/OrchardCore.Setup/Styles/setup.min.css" />

Sadly, this doesn’t work (at all) when hosting your application under a virtual path (for instance, http://localhost/orchard).

To fix that, all the assets should be referenced using the PathBase-relative syntax (~/). E.g:

<link type="text/css" rel="stylesheet" href="~/OrchardCore.Setup/Styles/setup.min.css" />

In this case, MVC will correctly compute the asset URL based on the PathBase defined by the IIS integration middleware.

@sebastienros I marked this ticket with P0 as it basically makes any OC deployment hosted under a virtual path unusable.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (15 by maintainers)

Most upvoted comments

Something like that should fix it for good but it will need some testing to ensure it doesn’t regress something else:

if (!String.IsNullOrEmpty(shellContext.Settings.RequestUrlPrefix))
{
    PathString prefix = "/" + shellContext.Settings.RequestUrlPrefix;
    httpContext.Request.PathBase += prefix;
    httpContext.Request.Path.StartsWithSegments(prefix, out PathString remainingPath);
    httpContext.Request.Path = remainingPath;
}