Copied to clipboard

Flag this post as spam?

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


  • bob 19 posts 39 karma points
    Jun 28, 2016 @ 14:58
    bob
    0

    No action was found on the controller UmbracoApiController

    Hi all,

    We moved our sites over to a new server and after moving we have encountered a server error 500 from an ajax call to a function that is included in a base class. I would like to know if anyone has encountered this before and how we can get round this.

    However as a workaround I am trying to tqke the code outside of the uncompiled class and add itto an umbraco api class again without success

    The following errors. -

    {,…} Message : "No HTTP resource was found that matches the request URI 'http://mywebsite.local/Umbraco/Api/MapApi/GetMapMarkers/4188'." MessageDetail : "No action was found on the controller 'MapApi' that matches the request."

    The UmbracoApiController processes Google Map data and Umbraco field data that should be passed to the calling AJAX -

    public class MapApiController : UmbracoApiController {

        [HttpPost]
        public void GetMapMarkers(int nodeId)
        {
            var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
            var contentItem = new Node(nodeId);
    
            // Get the map values
            var map = contentItem.GetProperty("mapLocation").Value;
            var lat = map.Split(',')[0];
            var lng = map.Split(',')[1];
            var zoom = map.Split(',')[2];
    
            var infoTitle = string.Empty;
            if (contentItem.GetProperty("mapLocationTitle") != null)
            {
                infoTitle = contentItem.GetProperty("mapLocationTitle").Value;
            }
    
            var infoText = string.Empty;
            if (contentItem.GetProperty("mapLocationInfo") != null)
            {
                infoText = contentItem.GetProperty("mapLocationInfo").Value;
            }
    
            string markerImageId;
            IPublishedContent markerImage;
    
            var mapSettings = JJWHelper.GetMapSettings();
            var markerImageUrl = mapSettings.MapPointerImage;
    
            if (contentItem.HasProperty("mapPointerImage"))
            {
                markerImageId = contentItem.GetProperty("mapPointerImage").Value;
                markerImage = umbracoHelper.TypedMedia(markerImageId);
                markerImageUrl = markerImage.Url;
            }
    
            var markers = new Marker[contentItem.ChildrenAsList.Count + 1];
    
            markers[0] = new Marker
            {
                MapLocation = map,
                Lat = Convert.ToDouble(lat),
                Lng = Convert.ToDouble(lng),
                Zoom = Convert.ToDouble(zoom),
                InfoTitle = !string.IsNullOrEmpty(infoTitle) ? infoTitle : " ",
                InfoText = !string.IsNullOrEmpty(infoText) ? infoText : " ",
                MarkerImageUrl = markerImageUrl
            };
    
            var loopCtr = 1;
    
            foreach (var pointer in contentItem.ChildrenAsList)
            {
                map = pointer.GetProperty("mapLocation").Value;
                lat = map.Split(',')[0];
                lng = map.Split(',')[1];
                infoTitle = pointer.GetProperty("mapLocationTitle") != null ? pointer.GetProperty("mapLocationTitle").Value : string.Empty;
                infoText = pointer.GetProperty("mapLocationInfo") != null ? pointer.GetProperty("mapLocationInfo").Value : string.Empty;
                markerImageId = pointer.GetProperty("mapPointerImage").Value;
                markerImage = umbracoHelper.TypedMedia(markerImageId);
    
                // Marker Image is mandatory, but issue (?) in Umbraco is allowing pointer node
                // to be published even though a pointer image has not been selected.
                // So, check that we actually have a marker image before adding it to the output array
                if (markerImage == null)
                {
                    continue;
                }
    
                markerImageUrl = markerImage.Url;
                markers[loopCtr] = new Marker
                {
                    MapLocation = map,
                    Lat = Convert.ToDouble(lat),
                    Lng = Convert.ToDouble(lng),
                    Zoom = Convert.ToDouble(zoom),
                    InfoTitle = !string.IsNullOrEmpty(infoTitle) ? infoTitle : " ",
                    InfoText = !string.IsNullOrEmpty(infoText) ? infoText : " ",
                    MarkerImageUrl = markerImageUrl
                };
    
                loopCtr++;
            }
    
            var json = new JavaScriptSerializer().Serialize(markers);
    
            HttpContext.Current.Response.ContentType = "application/json";
            HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
            HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddDays(10));
            HttpContext.Current.Response.Cache.SetETag(nodeId.ToString(CultureInfo.InvariantCulture));
            HttpContext.Current.Response.Write(json);
        }
    

    The AJAX call -

    var markers = (function () { var json = null; $.ajax({ 'async': false, 'global': false, 'url': "/Umbraco/Api/MapApi/GetMapMarkers/" + nodeId, 'dataType': "json", 'type': "POST", 'success': function (data) { json = data; } }); return json;}

    All help is appreciated on how to tackle this.

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Jun 29, 2016 @ 07:57
    Michaël Vanbrabandt
    0

    Hi bob,

    Make sure that you use the correct `HttpPost' attribute.

    Standard it will use the System.Web.Mvc.HttpPost attribute and you need the System.Web.Http.HttpPost attribute.

    /Michaël

  • bob 19 posts 39 karma points
    Jun 30, 2016 @ 10:00
    bob
    0

    I had this already Michael.

  • David Peck 687 posts 1863 karma points c-trib
    Jun 30, 2016 @ 13:16
    David Peck
    0

    I'm not clear why your nodeId is being added to the API url. Have you done some custom routes to enable this? Also editing the url in this way would fit with the concept of a GET rather than a POST.

    Is it as simple as you need to be supplying your node id to your AJAX request like this?

    var markers = (function () { var json = null; $.ajax({ 'async': false, 'global': false, 'url': "/Umbraco/Api/MapApi/GetMapMarkers", 'dataType': "json", 'type': "POST", data: { nodeid : nodeId} , 'success': function (data) { json = data; } }); return json; }

    NB: the data property

  • bob 19 posts 39 karma points
    Jun 30, 2016 @ 14:22
    bob
    0

    Hi David, Im getting the nodeId using this - var nodeId = window.mapContentId;

    This has to be passed to the controller so that it can process google map markers that are set in the backoffice.

    These variables then get sent back to the client to process the api.

    Initially the dev before me used 'url': "/base/Map/GetMapMarkers/" + nodeId, but as we have moved servers this call is generating an Internal Server Error 500 and this is why I took the code and tried to make it available via an UmbracoApi.

    I didnt realise it would be such a tricky job.

    Would you happen to know which file is the main base file so that I can try and set the proper permissions?

  • David Peck 687 posts 1863 karma points c-trib
    Jul 01, 2016 @ 08:10
    David Peck
    0

    I understand the need to pass in the nodeId, but I think it needs to be passed as part of the post data (as per my example) rather than part of the url. To pass it as part of the url doesn't fit with a post (although it could be done this way if you override the MVC routing).

    I'm afraid I don't understand "Would you happen to know which file is the main base file so that I can try and set the proper permissions?"

  • bob 19 posts 39 karma points
    Jul 01, 2016 @ 10:46
    bob
    0

    Hi david,

    I have changed track because I am now sure its got to do with the regional settings on the server being in another language other than english.. I have now reverted back to the original code and the base class and got the following error and according to this link it looks like the server guys are at fault -

    http://stackoverflow.com/questions/5275380/input-string-was-not-in-a-correct-format-2

    Error -

    STACKTRACE: at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Umbraco.Web.BaseRest.RestExtensionMethodInfo.Invoke(String[] parameters)

    INNEREXCEPTION: System.FormatException: Input string was not in a correct format. at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt) at System.Convert.ToDouble(String value) at JJWHotelsV6.Web.Api.Map.GetMapMarkers(Int32 nodeId)]]>

    The error above is showing me its related to the parsing of the string to a double and I have read a regional setting can replace a dot with a comma so hopefully this is going to be true fingers crossed!

    Lat = Convert.ToDouble(lat), Lng = Convert.ToDouble(lng), Zoom = Convert.ToDouble(zoom),

  • bob 19 posts 39 karma points
    Jul 01, 2016 @ 15:34
    bob
    0

    It was to do with the local server settings the dot really was getting replaced by a comma! All fixed now and many thanks for everyone who posted.

Please Sign in or register to post replies

Write your reply to:

Draft