Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • MuirisOG 382 posts 1283 karma points
    Jan 28, 2016 @ 14:26
    MuirisOG
    0

    Dear all,

    I know this goes against the grain, but I would like to turn off friendly URLs.

    Can you tell me which settings I need to change, so that links are to the page ID and not the wordy version, for example in menus and so on?

    Many thanks

  • Dirk De Grave 4539 posts 6012 karma points MVP 3x admin c-trib
    Jan 28, 2016 @ 15:16
    Dirk De Grave
    1

    I have no idea why you'd want this, but you could write your own UrlProvider implementation to just generate id's as url's. I don't think you need a IContentProvider to get page based on id, should already be in core.

    Here's a good article to get you started

    Cheers, Dirk

  • MuirisOG 382 posts 1283 karma points
    Feb 01, 2016 @ 10:15
    MuirisOG
    0

    Dirk

    many thanks for your reply.

    Our site is like Hogwarts - pages in the site move around constantly.

    We had a situation where over the space of a couple of years, our bookmarked content was generating page not found errors. We found the best approach was to use the page ID, and URL forwarding helped in those situations where we needed something more marketable and user friendly.

    Thanks, Maurice.

  • Jan Skovgaard 11264 posts 23591 karma points MVP 8x admin c-trib
    Feb 01, 2016 @ 11:12
    Jan Skovgaard
    2

    Hi MuirisOG

    Sounds like a better approach would be to use the 301 url tracker or simple url tracker packages, which makes sure that when the page is moved a 301 redirect to the new location is made, which means that bookmarked pages will be redirected to the new location as well.

    https://our.umbraco.org/projects/developer-tools/301-url-tracker or https://our.umbraco.org/projects/backoffice-extensions/simple-301/ (Not sure whether this package auto maps things) - Or you could roll your own perhaps.

    Just my 2 cents on a better approach.

    /Jan

  • MuirisOG 382 posts 1283 karma points
    Feb 01, 2016 @ 11:22
    MuirisOG
    0

    Thanks Jan,

    that's an excellent idea, and many thanks for the links.

  • MuirisOG 382 posts 1283 karma points
    Apr 06, 2016 @ 13:00
    MuirisOG
    0

    In answer to my own question, and for completeness, one really simple solution is to rewrite menus to output the id instead of the (nice)url.

    Thanks again.

  • Michaël Vanbrabandt 863 posts 3345 karma points c-trib
    Apr 06, 2016 @ 19:14
    Michaël Vanbrabandt
    1

    You can also create your custom UrlSegmentProvider. This is the part that renders each url for each node or segment.

    public class MyProvider : IUrlSegmentProvider
    {
      readonly IUrlSegmentProvider _provider = new DefaultUrlSegmentProvider();
    
      public string GetUrlSegment(IContentBase content)
      {
        if (content.ContentTypeId != 1234) return null;
        var segment = _provider.GetUrlSegment(content);
        return string.Format("{0}", content.Id);
      }
    }
    

    More information about this can be found here:

    https://our.umbraco.org/documentation/Reference/Routing/Request-Pipeline/outbound-pipeline

    /Michael

  • MuirisOG 382 posts 1283 karma points
    May 25, 2017 @ 11:00
    MuirisOG
    0

    Michaël

    thanks for this... I've finally got more time to look into this.

    I'll try the various solutions here, but I think I'll start with yours because it will match what we had on our old site.

    Muiris

  • MuirisOG 382 posts 1283 karma points
    Jun 01, 2017 @ 14:59
    MuirisOG
    0

    I've been trying to implement my own custom iUrlProvider and, although everything is working on the published site, I'm getting the following error in the backoffice. Do I need an iContentProvider to go with the iUrlProvider?

    Any help would be appreciated.

    An error occured
    
    Mapping types: Content -> String[] Umbraco.Core.Models.Content -> System.String[] Destination path: ContentItemDisplay.Urls.Urls Source value: Umbraco.Core.Models.Content
    
    
    Exception Details 
    AutoMapper.AutoMapperMappingException: Mapping types: Content -> String[] Umbraco.Core.Models.Content -> System.String[] Destination path: ContentItemDisplay.Urls.Urls Source value: Umbraco.Core.Models.Content 
    
    Stacktrace 
    at Umbraco.Web.Editors.ContentController.GetById(Int32 id)
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
    

    and there's this:

    System.UriFormatException: Invalid URI: Invalid port specified.
    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
       at System.Uri..ctor(String uriString)
       at Umbraco.Core.UriExtensions.MakeAbsolute(Uri uri, Uri baseUri)
       at Umbraco.Web.Routing.UrlProviderExtensions.GetContentUrls(IContent content, UmbracoContext umbracoContext)
       at lambda_method(Closure , IContent )
       at AutoMapper.DelegateBasedResolver`2.Resolve(ResolutionResult source) in c:\dev\AutoMapper\src\AutoMapper\Internal\DelegateBasedResolver2.cs:line 22
       at AutoMapper.NullReferenceExceptionSwallowingResolver.Resolve(ResolutionResult source) in c:\dev\AutoMapper\src\AutoMapper\Internal\NullReferenceExceptionSwallowingResolver.cs:line 18
       at AutoMapper.PropertyMap.<ResolveValue>b__6(ResolutionResult current, IValueResolver resolver) in c:\dev\AutoMapper\src\AutoMapper\PropertyMap.cs:line 127
       at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func)
       at AutoMapper.PropertyMap.ResolveValue(ResolutionContext context) in c:\dev\AutoMapper\src\AutoMapper\PropertyMap.cs:line 127
       at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, Object mappedObject, PropertyMap propertyMap) in c:\dev\AutoMapper\src\AutoMapper\Mappers\TypeMapObjectMapperRegistry.cs:line 116
    
  • MuirisOG 382 posts 1283 karma points
    Jun 02, 2017 @ 12:37
    MuirisOG
    1

    I've just been looking at the link below and I think I've found my problem. I was outputting the Page Id without a leading slash. I've added the slash now and it seems to have fixed my problem.

    http://www.ucodebase.be/blog/implementing-a-custom-urlprovider-in-umbraco-and-its-pitfalls/

    Edit: See this link for an excellent solution: https://our.umbraco.org/forum/using-umbraco-and-getting-started/77814-url-routing

Please Sign in or register to post replies

Write your reply to:

Draft