user3837891
user3837891

Reputation: 1

No links working in umbraco

the links are suddenly not working on our umbraco project. All links (umbraco links that is, like @Model.Url, not hard coded links) are not working, and just points to "localhost:8080".

I got a error, complaining about null-pointer exception at this code:

namespace Sk.Web.Routing
{
    public class ExternalUrlProvider : IUrlProvider
    {
        public string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
        {
            var node = umbracoContext.ContentCache.GetById(id);
            return node.HasValue("umbracoExternalUrl")
                ? node.GetPropertyValue<string>("umbracoExternalUrl")
                : "";
        }

        public IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
        {
            return Enumerable.Empty<string>();
        }
    }
}

When selecting nodes in the backoffice.

Also, when i debugged, i noticed the page-model missed the "umbracoExternalUrl" field. Weird.

Someone have any idea of what is going on here?

Upvotes: 0

Views: 457

Answers (1)

Digbyswift
Digbyswift

Reputation: 10400

There are actually two issues you are reporting here:

  • Links that just point to /
  • A null reference exception in your back office

Also, you should really quote the source of the code you are using (which is http://www.theoutfield.net/blog/2013/10/handling-external-urls-in-umbraco-6)

To clarify, the code is overriding what URL is returned by Umbraco when you call @Model.Url by using the one specified in the umbracoExternalUrl field.

If you read further into the article, you will see that you need to create an ApplicationEventHandler:

public class Bootstrapper : IApplicationEventHandler
{
    public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    { }

    public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        UrlProviderResolver.Current.InsertTypeBefore<DefaultUrlProvider, ExternalUrlProvider>();
    }

    public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    { }
}

Check that this hasn't been changed or removed.

If all your published site page links are displaying / then this means the code above is hitting the line node.HasValue("umbracoExternalUrl") and returning false. Therefore, you need to republish your site to update the XML and content cache.

If you are getting a null reference exception in the back office, it is almost certainly because there is no UmbracoContext. You need to provide more information in order for this to be answered, i.e. what action exactly in the back-office is causing the exception to occur. For example, is it a bespoke section or a multi-node picker?

If it is a custom section or datatype, you need to make sure the UmbracoContext is available to the code at runtime.

Note: Thanks to http://www.theoutfield.net/ for the code.

Upvotes: 0

Related Questions