Copied to clipboard

Flag this post as spam?

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


  • stephen 81 posts 122 karma points
    Oct 15, 2015 @ 09:39
    stephen
    0

    Angular Route to .net controller

    The following is really doing my head in...

    In the back office I reference a controller within my Angular resource file but constantly get Not Found (see image 2).

    The path is the exact same as other controller references, and they work. The method IS in the controller. Every time I add/change anything to do with angular I have to restart the appool (which is an utter pain) and rename EVERY fckn file.

    Maybe someone can shed some light cause I am running out of ideas.

    (I have changed the path referencing the controller between "umbraco/backoffice/.....etc" and "backoffice/.....etc)

    I have ensured the naming remains consistent between angular controller, angular resource and .net controller, ie "getNodeDetails" is used in all three.

    In Chrome toolsit indicates the correct path to the controller (see image 1) enter image description here

    enter image description here

  • Marc Goodson 2141 posts 14324 karma points MVP 8x c-trib
    Oct 15, 2015 @ 21:24
    Marc Goodson
    0

    Hi Stephen

    Which class does your .net api controller inherit from ?

    UmbracoAuthorizedApiController ?

    this effects how the request to your controller is routed:

    https://our.umbraco.org/documentation/Reference/Routing/Authorized/

    eg: backoffice/api/controllername/actionname

    There is a PluginController attribute that if you decorate your controller with, will direct the routing via the specified plugin area name

    eg [PluginController("pluginareaname")]

    would route via backoffice/pluginareaname/controllername/actionname

    not sure if that helps you pinpoint why it is not working ?

    regards

    marc

  • stephen 81 posts 122 karma points
    Oct 16, 2015 @ 08:04
    stephen
    0

    Hi marc Yes I am using UmbracoAuthorizedApicontroller and it is decorated as you indicated. In this instance it is decorated as:

     [Umbraco.Web.Mvc.PluginController("TPS")]
    

    so in my resource.js I am referencing:

    return $http.get("backoffice/TPS/EventsApi/getNodeDetails?nodeid=" + nodeid);
    

    On my server the file resides in the path:

    umbraco/backoffice/TPS/[name of controller.cs]

    I thought it may be a caching issue with the server and restarted the app pool then even restarted the server but no change.

    One thing to note is that I am nesting references to angular controllers, ie:

    <div ng-controller="My.cmsGetAttendeeList97">
            <div class="panel panel-default" ng-repeat="event in events">..code
                            <div ng-controller="My.cmsGetNodeDetails14" >...code
    

    Each js controller references a specific resource.js file and subsequently they in turn reference the same .net controller.

    The manifest file references all the appropriate controller.js and resource.js files etc.

    thanks

  • Harshit 64 posts 226 karma points
    Oct 16, 2015 @ 06:38
    Harshit
    0

    Hi Stephen,

    I presuming your API is EventApicontroller and method name is getNodeDetails if so, then path should be:

     $http({ method: 'GET/POST', url: '/umbraco/api/EventAPI/getNodeDetails/', params: { if any })
    

    url should be : '/umbraco/api/EventAPI/getNodeDetails/'

    hope it will help.

    Harshit

  • stephen 81 posts 122 karma points
    Oct 16, 2015 @ 08:06
    stephen
    0

    Hi Harshit,

    your code example is not what I am using. See my response to Marc. thanks

  • Marc Goodson 2141 posts 14324 karma points MVP 8x c-trib
    Oct 17, 2015 @ 12:35
    Marc Goodson
    1

    Stephen

    couple of thoughts (not sure you have posted the signature of your controller above) but

    try passing the nodeid as just a parameter called id ie so, your request is

    backoffice/TPS/EventsApi/getNodeDetails/1234

    where 1234 is accepted as a parameter called id

    Then try switching this parameter to be of type string (if it is currently an integer)

    Final suggestion: is are you decorating your controller with [HttpGet] ?

    if so make sure it is resolved to System.Web.Http namespace, and not System.Web.Mvc

    regards

    Marc

  • stephen 81 posts 122 karma points
    Oct 21, 2015 @ 10:23
    stephen
    0

    Thanks Marc. I'll try this out and get back.

    Stephen

Please Sign in or register to post replies

Write your reply to:

Draft