gpt4 book ai didi

c# - Windows Azure Dnn Web API 路由未注册

转载 作者:行者123 更新时间:2023-12-03 01:55:17 25 4
gpt4 key购买 nike

我正在使用 angularJS 在 DotNetNuke 上实现一个模块。我已经在本地测试了该模块,它工作正常,但是一旦我在生产中安装该模块,我就会收到此错误:

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

需要采取哪些步骤才能向 Azure 注册这些路由?

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

最佳答案

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

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

关于c# - Windows Azure Dnn Web API 路由未注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23344739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com