U4-5407 - UmbracoAuthorizedApiController routing no longer supports parameters in URL

Created by Tom Fulton 27 Aug 2014, 04:44:00 Updated by Shannon Deminick 26 Jun 2017, 05:40:42

Relates to: U4-5384

In the Phoenix Converters package, we have a method with some parameters defined in an UmbracoAuthorizedApiController: ([https://github.com/imulus/PhoenixConverters/blob/master/src/PhoenixConverters/Controllers/PhoenixApiController.cs#L106-L123 source])

namespace PhoenixConverters.Controllers
{
    public class PhoenixApiController : UmbracoAuthorizedApiController
    {
	    [HttpGet]
        public object GetDataTypesByAlias(string dataTypeAlias)
        {
            ....
	    }
    }
}

Unsure if this is best practice or not, but we created a custom route for it a long time ago:

RouteTable.Routes.MapHttpRoute(
    "PhoenixApiDataTypeByAlias",
    "umbraco/backoffice/PhoenixApi/DataType/{action}/{dataTypeAlias}",
    new { controller = "PhoenixApi" });

We are accessing that via this URL, passing the parameter right in the URL:

umbraco/backoffice/PhoenixApi/DataType/GetDataTypesByAlias/Umbraco.MultipleMediaPicker

Pre-7.5, we this works and we get results, but in 7.5 and 7.6 we're now seeing this:

{
    Message: "An error has occurred.",
    ExceptionMessage: "Object reference not set to an instance of an object.",
    ExceptionType: "System.NullReferenceException",
    StackTrace: " at Umbraco.Web.WebApi.NamespaceHttpControllerSelector.SelectController(HttpRequestMessage request) at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncInternal(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)"
}

Everything works fine if we access the URLs like this instead (naming parameters via querystrings):

umbraco/backoffice/PhoenixApi/DataType/GetDataTypesByAlias/?dataTypeAlias=Umbraco.MultipleMediaPicker`

We should probably get this updated to use [PluginController] and the default route Umbraco creates, but just thought I'd mention this in case it's relevant to anything else.

Comments

Tom Fulton 27 Aug 2014, 04:44:39

Possibly related?


Shannon Deminick 27 Aug 2014, 04:49:17

If you are going to custom route your own controllers then please don't use the auto-routed Umbraco ones. You now have two routes for the same thing.

If you want to get rid of the error, then you need to assign the DataTokens of your route to an instance of an object. Though the null ref exception should have been fixed in rev: ebf24d69b5c05bd1f5682f9ef53f1a8d20bb4afa which as far as i can tell should be in 7.1.5


Shannon Deminick 27 Aug 2014, 04:50:46

It's also worth noting that the hard coding of 'umbraco/backoffice' isn't particularly great because the 'umbraco' part is configurable.


Shannon Deminick 26 Jun 2017, 05:40:43

Closing issue due to inactivity - see blog post for details https://umbraco.com/blog/issue-tracker-cleanup/


Priority: Normal

Type: Bug

State: Closed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.1.5, 7.1.6

Due in version:

Sprint:

Story Points:

Cycle: