2014-04-28 69 views
1

我正在使用angularJS在DotNetNuke上實現一個模塊。我在本地測試的模塊,它工作正常,但是一旦我安裝模塊生產我得到這個錯誤回:Windows Azure Dnn Web API路由不註冊

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

都是應採取以註冊這些路線與蔚藍的必要步驟?

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

回答

2

我終於萬一有人想出了其他的問題找到了這個問題。我的註冊路由器負載以前看起來像這樣

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