Trailing slash on mediafiles

GOSSO
Member since: 2007
 

Hi all,

Update from CMS6r2 to CMS v 7.19.2 (webforms)

I have a trailing slash by default on mediafiles (domain.com/en/globalassets/folder/filename.pdf/), and i don want that.

I want to remove trailing slashes on mediafiles. Shouldn't that automaticly? Any suggestions?

Tried the IIS rewrite 2.0 on IIS7, but i didnt get it to work other then the root page. It makes eternal redirects on all other pages.

Regards

#120166
Apr 13, 2015 8:46
valdis
Member since: 2011
 

Will this help? However I guess this may affect all content types - not only media.

EPiServer.Web.Routing.ContentRoute.UseTrailingSlash = false;

 

#120170
Edited, Apr 13, 2015 10:04
GOSSO
Member since: 2007
 

No, niether true or false do any difference.

#120171
Apr 13, 2015 10:21
Johan Björnfot
Member since: 2004
 

Hi

You should not need to do anything to prevent trailing slash for media files, the generated virtual path for media should not have a trailing slash.

Have you converted your media files from VPP based to content using the Migration tool?

Also the url for media served from globalassets should not have a language segment (that is it should not contain a "/en/" segment), that indicates that it might be the wrong route that generates the virtual path (there are different routes registered for media and e.g. pages).

#120175
Apr 13, 2015 11:33
GOSSO
Member since: 2007
 

Thanks, It is probably "wrong route that generates the virtual path" since i do have "en" lang code in url. How proceed with that?

Yes i used the VPP Migration tool

Debugging example:

link.NavigateUrl = "/link/2e7e4d4ba521459fbfe88e73094639c7.aspx?id=28717";

Generated link = /sv/globalassets/documents/about/corporate-governance/sv-2010-rapport.pdf/

All help is appreciated.

Regards

#120179
Apr 13, 2015 11:49
Johan Björnfot
Member since: 2004
 

Could you verify that the media indeed is under GlobalAssetsRoot? 

If you go to admin mode under access rigths you should see the different parts of the site under the root node. You should see a node called "For all sites" or similar, verify that the migrated media from the migration tool is located under that node.

Then from SQL Managment studio you can call

exec netContentRootList 

and verify that the the id returned as GlobalAssets is the same id as the node "For all sites" described in set access rights above.

#120187
Apr 13, 2015 13:37
GOSSO
Member since: 2007
 

Thanks Johan,

Under "Global Assets" is all my migrated media. There is no "For all sites". And yes it is the same id as in exec netContentRootList "GlobalAssets".

What route my be wrong? how to check that?

#120189
Apr 13, 2015 13:48
Johan Björnfot
Member since: 2004
 

From the description I would guess that it is the route named "pageroot" that generates the virtual path, but it should be the route named "Media". You could in a debugger in a breakpoint look at static property System.Web.Routing.RouteTable.Routes.

There you should see all routes registered and more specifiacally there should be one called "Media" before the one called "pageroot".

You can also in a debugger verify which route that generates a virtual path. You can do that by some code like:

            var values = new RouteValueDictionary();
            values[RoutingConstants.NodeKey] = new ContentReference(28717);
            var virtualPath = System.Web.Routing.RouteTable.Routes.GetVirtualPath(System.Web.HttpContext.Current.Request.RequestContext, values);
            var routeName = (virtualPath.Route as ContentRoute).Name;
#120190
Apr 13, 2015 14:09
GOSSO
Member since: 2007
 

Object VirtualPath in your code is "/EPiServer/EPiServer.Commerce.AddOns.Manager?node=28717"

We have 34 Routes

no 10 is EPiServer/EPiServer.Commerce.AddOns.Manager/{*path}

no 25 is Media_Global

no 30 is PageRoot

Suggestion?

#120192
Apr 13, 2015 15:29
Johan Björnfot
Member since: 2004
 

my assumption was that 28717 is the id of an existing media item? 

Anyway it seems there is some commerce route that handles the request before it reaches the cms routes. You could try to modify the code as:

         var values = new RouteValueDictionary();
            values[RoutingConstants.NodeKey] = new ContentReference(28717);
            foreach (var cmsRoute in System.Web.Routing.RouteTable.Routes.OfType<ContentRoute>())
            {
                var virtualPath = cmsRoute.GetVirtualPath(System.Web.HttpContext.Current.Request.RequestContext, values);
                if (virtualPath != null)
                {
                    System.Diagnostics.Debug.WriteLine("Route is " + cmsRoute.Name);
                }
            }
#120193
Apr 13, 2015 15:39
GOSSO
Member since: 2007
 

Yes 28717 is a PDF under globalassets.

OUTPUT:

Route is Media_Global
Route is Media_Site
Route is pageroot

.OfType<ContentRoute> sorts out to 13 Routes..

#120194
Apr 13, 2015 15:51
GOSSO
Member since: 2007
 

EPiServer/EPiServer.Commerce.AddOns.Manager/{*path} is typeOf System.Web.Routing.Route

#120195
Apr 13, 2015 15:54
Johan Björnfot
Member since: 2004
 

Ok, so then the media route actually handles the content. What does the virtual paths look like for the different routes, e.g. change output to:

var values = new RouteValueDictionary();
            values[RoutingConstants.NodeKey] = new ContentReference(28717);
            foreach (var cmsRoute in System.Web.Routing.RouteTable.Routes.OfType<ContentRoute>())
            {
                var virtualPath = cmsRoute.GetVirtualPath(System.Web.HttpContext.Current.Request.RequestContext, values);
                if (virtualPath != null)
                {
                    System.Diagnostics.Debug.WriteLine(String.Format("Route is '{0}' with path '{1}'", cmsRoute.Name, virtualPath.VirtualPath));
                }
            }
#120196
Apr 13, 2015 15:56
GOSSO
Member since: 2007
 

looking good

Route is 'Media_Global' with path 'globalassets/documents/about/corporate-governance/sv-2010-bolagsstyrningsrapport.pdf'
Route is 'Media_Site' with path 'siteassets/documents/about/corporate-governance/sv-2010-bolagsstyrningsrapport.pdf'
Route is 'pageroot' with path 'globalassets/documents/about/corporate-governance/sv-2010-bolagsstyrningsrapport.pdf'

but isnt the problem that the other Routes typeOf System.Web.Routing.Route is handling the request before?

I tested:

 foreach (var cmsRoute in System.Web.Routing.RouteTable.Routes.OfType<Route>())
            {
                var virtualPath = cmsRoute.GetVirtualPath(System.Web.HttpContext.Current.Request.RequestContext, values);
                if (virtualPath != null)
                {
                    System.Diagnostics.Debug.WriteLine("Route is " + cmsRoute.Url + " // " + cmsRoute.RouteHandler.ToString());
                }
            }

Route is EPiServer/EPiServer.Commerce.AddOns.Manager/{*path} // System.Web.Mvc.MvcRouteHandler
Route is ProductInCartOrWishList/Edit/{id} // System.Web.Mvc.MvcRouteHandler
Route is CustomerProperties/Edit/{id} // System.Web.Mvc.MvcRouteHandler
Route is OrdersFrequency/Edit/{id} // System.Web.Mvc.MvcRouteHandler
Route is RecentSpent/Edit/{id} // System.Web.Mvc.MvcRouteHandler
Route is RecentOrders/Edit/{id} // System.Web.Mvc.MvcRouteHandler
Route is  // EPiServer.Web.Routing.MultiplexingRouteHandler
Route is  // EPiServer.Web.Routing.MultiplexingRouteHandler
Route is  // EPiServer.Web.Routing.MultiplexingRouteHandler

Thank you for helping, routing is not my domain.

#120197
Apr 13, 2015 16:04
Johan Björnfot
Member since: 2004
 

If another route than a CMS route would have taken the request then the url would probably have been something like the ones you see above. But in your case it looks almost correct except for the language segment and the trailing slash.

Could it be that you have some old custom FURL module running. If you look in your config under http modules do you see an entry of EPiServer.Web.RoutingUrlRewriteModule? And also under <episerver> section is there any node <urlRewrite> and if so what is the content there?

#120198
Apr 13, 2015 16:11
GOSSO
Member since: 2007
 

yes we do have in episerver.config...

 <urlRewrite defaultProvider="EPiServerFriendlyUrlRewriteProvider">
    <providers>
      <clear />
      <add name="EPiServerFriendlyUrlRewriteProvider" type="EPiServer.Web.FriendlyUrlRewriteProvider,EPiServer" />
      <add description="EPiServer identity URL rewriter" name="EPiServerIdentityUrlRewriteProvider" type="EPiServer.Web.IdentityUrlRewriteProvider,EPiServer" />
      <add description="EPiServer bypass URL rewriter" name="EPiServerNullUrlRewriteProvider" type="EPiServer.Web.NullUrlRewriteProvider,EPiServer" />
      <add name="HierarchicalUrlRewriteProvider" type="EPiServer.Web.HierarchicalUrlRewriteProvider,EPiServer" />
    </providers>
  </urlRewrite>
#120200
Apr 13, 2015 16:17
Johan Björnfot
Member since: 2004
 

Try to either outcomment the whole section or change defaultProvider to HierarchicalUrlRewriteProvider

#120201
Apr 13, 2015 16:18
GOSSO
Member since: 2007
 

That seems to help!! is EPiServer.Web.FriendlyUrlRewriteProvider legacy?

#120202
Apr 13, 2015 16:21
Johan Björnfot
Member since: 2004
 

Yes, previously to CMS7 we had our own routing framework (UrlRewriteProviders), from CMS7 and forward we have a new implemenation based on .NET routing. The reason the old one is still possible to run is to support if someone has written their own UrlRewriteProvider with custom logic.

#120203
Apr 13, 2015 16:24
GOSSO
Member since: 2007
 

Johan, yesterday i did only look the html output.... now when i click the link or type in "/globalassets/report.pdf"

it does a 302 redir and put a trailing trash "/globalassets/report.pdf/" in the webadress, doh! (no good for siteseeker indexer)

I have removed FriendlyUrlRewriteProvider from web.config, default is set to "HierarchicalUrlRewriteProvider".

Same if i remove all UrlRewrite providers in Episerver.config

If I set  EPiServer.Web.Routing.ContentRoute.UseTrailingSlash = false; it works, but i want tailing slash on all other URLs except mediafiles...

Any idea what now?

I could use UrlRewrite in IIS but i would like to find the root cause.

#120276
Apr 14, 2015 14:24
Johan Björnfot
Member since: 2004
 

If you look in web.config under httpmodules, do you have an entry of EPiServer.Web.RoutingUrlRewriteModule? If you instead have an entry of type EPiServer.Web.UrlRewriteModule try to change to EPiServer.Web.RoutingUrlRewriteModule.

#120277
Apr 14, 2015 14:30
GOSSO
Member since: 2007
 

Thanks Johan!

#120278
Apr 14, 2015 14:40
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.