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.
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.
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.
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
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.
Friendly URLs
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
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
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.
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
Thanks Jan,
that's an excellent idea, and many thanks for the links.
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.
You can also create your custom
UrlSegmentProvider
. This is the part that renders each url for each node or segment.More information about this can be found here:
https://our.umbraco.org/documentation/Reference/Routing/Request-Pipeline/outbound-pipeline
/Michael
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
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.
and there's this:
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
is working on a reply...