Umbraco 8 - UrlProviderResolver does not exist in the current context
Hi,
I am looking to add extra functionality to Umbraco 8 using Compose, and specifically Umbraco.Web.Routing.UrlProviderResolver
Has UrlProviderResolver been removed from Umbraco 8, and if so what replaces this functionality?
I am looking to override the Routing with a view to creating our own headless CMS
The code snippet is below, but wherever I have tried to implement UrlProviderResolver I have the same error "The name UrlProviderResolver does not exist in the current context"
Here is my code snippet:
using AutoMapper;
using System.Web.Routing;
using CRest.CMTRest.MappingProfile;
using CRest.CMTRest.Routing;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Web;
using Umbraco.Web.Routing;
namespace UMB8_CRest
{
public class CRestStartUp : IUserComposer
{
public void Compose(Composition composition)
{
// Append our component to the collection of Components
// It will be the last one to be run
composition.Components().Append<MyComponent>();
}
public class MyComponent : IComponent
{
// initialize: runs once when Umbraco starts
public void Initialize()
{
InitAutoMapper();
InitRouting();
}
public void InitAutoMapper()
{
Mapper.Initialize(cfg => {
cfg.AddProfile<OurRestMappingProfile>();
});
}
public void InitRouting()
{
RouteTable.Routes.IgnoreStandardExclusions();
Umbraco.Web.Routing.UrlProvider
UrlProviderResolver.Current.InsertTypeBefore<DefaultUrlProvider, OurRestUrlProvider>();
}
// terminate: runs once when Umbraco stops
public void Terminate()
{
}
}
}
The line which is at the core of this issue is:
UrlProviderResolver.Current.InsertTypeBefore
I appreciate that Umbraco 8 is only just out of the blocks, and the documentation is in it early days.
Can someone please shed some light on how to handle this in the new Umbraco 8 build. What has replaced UrlProviderResolver, and do you have any examples on how to implement it?
I've been looking into a similar implementation for Umbraco 8 and this is what I've come up with:
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class ApplicationStartUp : IUserComposer
{
public void Compose(Composition composition)
{
composition.UrlProviders().InsertBefore<DefaultUrlProvider, MyUrlProvider>();
composition.ContentFinders().InsertBefore<ContentFinderByUrl, MyContentFinder>();
}
}
public class MyUrlProvider : IUrlProvider
{
public UrlInfo GetUrl(UmbracoContext umbracoContext, IPublishedContent content, UrlProviderMode mode, string culture, Uri current)
{
throw new NotImplementedException();
}
public IEnumerable<UrlInfo> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
{
throw new NotImplementedException();
}
}
public class MyContentFinder : IContentFinder
{
public bool TryFindContent(PublishedRequest frequest)
{
throw new NotImplementedException();
}
}
There are 2 issues I'm having though:
For some reason you have to disable the Url tracking, this isn't a big deal for what I'm working on but might be for others
The use of the Url Provider itself can be intermittent on the site restart, for some reason the Umbraco codebase doesn't always use the Provider and the site needs to be restarted to pick it up.
Hi Simon,
Thank you for this reply, I will look at this later and get back to you with some feedback and my experience of using/developing this code.
Kind regards,
Pete
I seem to have resolved the issues I was having so now the code is:
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class UrlProviderStartUp : IUserComposer
{
public void Compose(Composition composition)
{
composition.UrlProviders().InsertBefore<DefaultUrlProvider, MyUrlProvider>();
}
}
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class ContentFinderStartUp : IUserComposer
{
public void Compose(Composition composition)
{
composition.ContentFinders().InsertBefore<ContentFinderByUrl, MyContentFinder>();
}
}
public class MyUrlProvider : IUrlProvider
{
public UrlInfo GetUrl(UmbracoContext umbracoContext, IPublishedContent content, UrlProviderMode mode, string culture, Uri current)
{
throw new NotImplementedException();
}
public IEnumerable<UrlInfo> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
{
throw new NotImplementedException();
}
}
public class MyContentFinder : IContentFinder
{
public bool TryFindContent(PublishedRequest frequest)
{
throw new NotImplementedException();
}
}
Umbraco 8 - UrlProviderResolver does not exist in the current context
Hi, I am looking to add extra functionality to Umbraco 8 using Compose, and specifically Umbraco.Web.Routing.UrlProviderResolver Has UrlProviderResolver been removed from Umbraco 8, and if so what replaces this functionality? I am looking to override the Routing with a view to creating our own headless CMS The code snippet is below, but wherever I have tried to implement UrlProviderResolver I have the same error "The name UrlProviderResolver does not exist in the current context"
Here is my code snippet:
The line which is at the core of this issue is: UrlProviderResolver.Current.InsertTypeBefore
I appreciate that Umbraco 8 is only just out of the blocks, and the documentation is in it early days. Can someone please shed some light on how to handle this in the new Umbraco 8 build. What has replaced UrlProviderResolver, and do you have any examples on how to implement it?
Thank you and kind regards,
Peter
Hi,
I've been looking into a similar implementation for Umbraco 8 and this is what I've come up with:
There are 2 issues I'm having though:
Hope this helps point you in the right direction.
Hi Simon, Thank you for this reply, I will look at this later and get back to you with some feedback and my experience of using/developing this code. Kind regards, Pete
Hi Peter,
I seem to have resolved the issues I was having so now the code is:
This appears to work everytime now.
is working on a reply...