Windows Azure Dnn Web API路由未注册

本文关键字:路由 注册 API Web Azure Dnn Windows | 更新日期: 2023-09-27 18:00:46

我正在使用angularJS在DotNetNuke上实现一个模块。我已经在本地测试了该模块,它运行良好,但一旦我在生产中安装该模块,我就会返回这个错误:

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

是否需要采取措施才能在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, "{ }");
            }
        }

角度服务

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;
    }
});

Windows Azure Dnn Web API路由未注册

我终于解决了这个问题,以防其他人发现这个问题。我的注册路线过载以前看起来像这个

        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]" });

为了通过Azure注册路由,由于某些原因,此过载不起作用。我不得不把它改成这个:

        mapRouteManager.MapHttpRoute("Programs",
                    "default",
                    "{controller}/{action}",
                    new[] { "HyperLib.Modules.Programs.Services" });