Question

I'm implementing a module on DotNetNuke using angularJS. I've tested the module locally and it works fine, however once I install the module in production I get this error back:

[WebAddress]/Programs/DesktopModules/Controls/Programs/ProgramApi/GetList?categoryId=-1&index=0&results=20 404 (Not Found) 

Are there steps needed to be take in order to register these routes with azure?

Web Api

namespace HyperLib.Modules.Programs.Services
{
    [SupportedModules("Programs")]
    public class ProgramApiController : DnnApiController
    {
 [HttpGet, ValidateAntiForgeryToken]
        [DnnModuleAuthorize(AccessLevel = DotNetNuke.Security.SecurityAccessLevel.View)]
        public HttpResponseMessage GetList(int categoryId, int index, int results)
        {
            try
            {
                Components.ProgramController pc = new Components.ProgramController();

                bool isEditable = false;
                if (DotNetNuke.Common.Globals.IsEditMode() && ModulePermissionController.CanEditModuleContent(this.ActiveModule))
                    isEditable = true;

                if (categoryId != -1)
                {
                    var programs = pc.GetItemsByCondition<Program>("where ModuleId = @0 and ProgramCategoryId = @1", this.ActiveModule.ModuleID, categoryId)
                        .Where(w => w.EndDate >= DateTime.Now)
                        .Skip(index * results)
                        .Take(results)
                        .Select(s => new ProgramViewModel(s, false, isEditable, this.ActiveModule.ModuleID.ToString(), this.ActiveModule.TabID.ToString()));
                    return Request.CreateResponse(HttpStatusCode.OK, JsonConvert.SerializeObject(programs));
                }
                else
                {
                    var programs = pc.GetItems<Program>(this.ActiveModule.ModuleID)
                       .Where(w => w.EndDate >= DateTime.Now)
                       .Skip(index * results)
                       .Take(results)
                       .Select(s => new ProgramViewModel(s, false, isEditable, this.ActiveModule.ModuleID.ToString(), this.ActiveModule.TabID.ToString()));
                    return Request.CreateResponse(HttpStatusCode.OK, JsonConvert.SerializeObject(programs));
                }

            }
            catch (Exception exc)
            {
                Exceptions.LogException(exc);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "{ }");
            }
        }

Angular Service

programs.service('programService', function ($http, $q) {

    var baseUrl = sf.getServiceRoot('Programs') + 'Api/ProgramApi';
    var config = {
        headers: {
            'ModuleId': sf.getModuleId(),
            'TabId': sf.getTabId(),
            'RequestVerificationToken': sf.getAntiForgeryValue()
        }
    };

    this.getList = function (index, count, catId) {
        var deferred = $q.defer();

        config.params = {
            index: index,
            results: count,
            categoryId: catId
        }

        $http.get(baseUrl + '/GetList', config).success(function (data) {
            deferred.resolve($.parseJSON(JSON.parse(data)));
        }).error(function (error) {
            deferred.reject(error);
        });

        return deferred.promise;
    }
});
Was it helpful?

Solution

I finally figured out the problem in case anyone else finds this problem. My Register Routes over load previously looked like this

        mapRouteManager.MapHttpRoute(
            moduleFolderName: "Programs",
            routeName: "Programs",
            url: "{controller}/{action}",
            defaults: new { controller = "ProgramApi", action = "GetList", id = System.Web.Mvc.UrlParameter.Optional },
            namespaces: new string[] { "[Namespace]" });

In order to register the routes through Azure, for some reason this overload doesn't work. I had to change it to this:

        mapRouteManager.MapHttpRoute("Programs",
                    "default",
                    "{controller}/{action}",
                    new[] { "HyperLib.Modules.Programs.Services" });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top