Copied to clipboard

Flag this post as spam?

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


  • Ross Ekberg 124 posts 365 karma points
    Jul 06, 2022 @ 14:35
    Ross Ekberg
    0

    Backoffice Routing

    I am attempting to make a backoffice API. Here is my controller (in the App_Code folder)...

    namespace My.Controllers
    {    
        [Umbraco.Web.Mvc.PluginController("My")]
        public class SubscriptionPickerAPIController : UmbracoAuthorizedJsonController
        {
            public string GetAll()
            {
                <some code>
            }
        }    
    }
    

    I attempt to call this api via angular like so...

    angular.module('umbraco.resources').factory('SubscriptionPickerResource',
        function ($q, $http) {
            return {
                getAll: function () {
                    return $http.get("backoffice/My/SubscriptionPickerApi/GetAll");
                }
            };
        }
    ); 
    

    However, in the backoffice, I get the following error:

    Request error: The URL returned a 404 (not found): backoffice/My/SubscriptionPickerAPI/GetAll

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jul 06, 2022 @ 14:40
    Dan Diplo
    0

    I think your API URL should be:

    /umbraco/backoffice/My/SubscriptionPickerApi/GetAll

    See https://our.umbraco.com/documentation/reference/routing/Authorized/

  • Ross Ekberg 124 posts 365 karma points
    Jul 06, 2022 @ 14:48
    Ross Ekberg
    0

    No luck. I have tried all the following paths. None have worked...

    backoffice/My/SubscriptionPickerApi/GetAll

    /backoffice/My/SubscriptionPickerApi/GetAll

    ~/backoffice/My/SubscriptionPickerApi/GetAll

    umbraco/backoffice/My/SubscriptionPickerApi/GetAll

    /umbraco/backoffice/My/SubscriptionPickerApi/GetAll

    ~/umbraco/backoffice/My/SubscriptionPickerApi/GetAll

  • Ross Ekberg 124 posts 365 karma points
    Jul 06, 2022 @ 15:07
    Ross Ekberg
    0

    Could it have something to do with HTTPS? I notice when I just go to the URL directly, https://domain.com/umbraco/backoffice/My/subscriptionpickerapi/getall, I get...

    No HTTP resource was found that matches the request URI

    Could it have something to do with the fact the site is on an SSL, but umbraco is looking for HTTP?

  • Ross Ekberg 124 posts 365 karma points
    Jul 07, 2022 @ 22:13
    Ross Ekberg
    0

    I checked my debugger, and it says it's attempting to use the secure URL, but it comes back 404. So the call is correctly secure. But it seems the controller route just doesn't exist.

    I have a testing environment with the exact same build on it, but without a security cert. It works just fine there.

    This really makes me think this has something to do with HTTPS, like the routing isn't creating a route for HTTPS, only HTTP. Can this be possible?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jul 08, 2022 @ 10:18
    Dan Diplo
    0

    Is this for v7? Have you looked at the umbracoUseSSL key in web.config? You can set it to true or false.

    <add key="umbracoUseSSL" value="true" />

    See https://our.umbraco.com/Documentation/Reference/Security/use-https-v8

    You can also set redirects in IIS to always redirect HTTP to HTTPS when using a secure certificate, which should avoid such problems.

  • Ross Ekberg 124 posts 365 karma points
    Jul 18, 2022 @ 12:18
    Ross Ekberg
    0

    Yes, this is v7. 'umbracoUseSSL' is set to 'true' and HTTPS redirects are enabled.

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Jul 08, 2022 @ 10:50
    Nik
    0

    Hey Ross,

    It would be worth having a read of this blog post (sorry it's a bit of self promotion)

    https://justnik.me/blog/accessing-config-settings-in-your-umbraco-angular-controller

    This helps you extend a JS helper with the base route of your controller, which then means you can access it from a JS object and then append on the very last segment (the action part) so you don't have to construct it yourself.

    One thing to note, is you get that same error for the following reasons:

    1. If there is a redirect going on which changes posts/gets (e.g. enforcing HTTPS or www vs non-www
    2. The action is expecting additional parameters / body content but they aren't provided.

    Hope that helps,

    Nik

  • Ross Ekberg 124 posts 365 karma points
    Jul 19, 2022 @ 19:50
    Ross Ekberg
    0

    I just don't understand what would be different between my live and test environments. The biggest thing is that live is over HTTPS, while test is just HTTP. Everything works just fine in my test environment.

Please Sign in or register to post replies

Write your reply to:

Draft