Copied to clipboard

Flag this post as spam?

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


  • Søren Mastrup 122 posts 563 karma points c-trib
    Jan 11, 2016 @ 14:54
    Søren Mastrup
    0

    Open requests (Umbraco API)

    I am currently experiencing issues when using the UmbracoApiController.

    Open requests on the IIS

    How can I make sure that connections to the API is closed after about 30 seconds?

    This is my code for the "GetTransportMethodFromId":

    using System.Web;
    using System.Collections.Generic;
    using System.Linq;
    using Umbraco.Web.WebApi;
    using Umbraco.Core.Models;
    using TransportMethods.Models;
    using Umbraco.Web;
    using WebApi.OutputCache.Core;
    using WebAPI.OutputCache;
    
    namespace TransportMethods.Controllers
    {
        public class TransportMethodsController : UmbracoApiController
        {
            string rootId = umbraco.cms.businesslogic.web.Domain.GetRootFromDomain(HttpContext.Current.Request.Url.Host).ToString();
    
            [CacheOutput(ServerTimeSpan = 86400)]
            public IEnumerable<TransportMethod> GetTransportMethodFromId(int Id)
            {
    
                HttpContext.Current.Response.ContentType = "application/json";
    
                UmbracoHelper help = new UmbracoHelper(UmbracoContext);
    
                return help.TypedContent(Id).GetPropertyValue<IEnumerable<IPublishedContent>>("transportMethods").Select(obj => new TransportMethod()
                {
                    TransportName = help.Field(obj, "transportName").ToString(),
                    TransportCode = help.Field(obj, "transportCode").ToString()
                });
            }
    
            [CacheOutput(ServerTimeSpan = 86400)]
            public List<TransportMethod> GetTransportMethodFromIds(string Id)
            {
                var transportnamesList = new List<TransportMethod>();
    
                HttpContext.Current.Response.ContentType = "application/json";
                string[] transportCodes = Id.Split(',');
                var firstNodeId = Umbraco.TypedContent(rootId).Descendants().Where(x => x.DocumentTypeAlias == "HotellerOgPriser").Where("Visible").Where("getTransportNames").First().Id;
    
                foreach(var transportCode in transportCodes){
                    var transportname = new TransportMethod();
    
                    var tItems = Umbraco.TypedContent(firstNodeId).GetPropertyValue<IEnumerable<IPublishedContent>>("transportMethods").Where(x => x.GetPropertyValue<string>("transportCode") == transportCode);                 
                    transportname.TransportCode = transportCode;
                    transportname.TransportName = tItems.First().GetPropertyValue<string>("transportName");
                    transportnamesList.Add(transportname);
                }
    
                return transportnamesList;
            }
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft