Web API调用从DNN站点返回404

时间:2017-12-19 13:04:11

标签: c# dotnetnuke

首先抱歉,如果我错误地在SO上提出这个问题。我有一个第三方库([Link][1]),其中编写了Web API逻辑。我有一个DNN Custom模块,我在其中显示PDF查看器。但是在加载查看器时,此调用404会出现http://dnndev.me/dvapi3/docuvieware3api/init/1异常。

我不确定问题是在DNN或第三方工具中发生的确切位置。对此问题的任何帮助都将受到高度赞赏。

更新

WebAPI控制器元数据

namespace GdPicture14.WEB
{
public class DocuVieware3ApiController : System.Web.Http.ApiController
{
    public DocuVieware3ApiController();
    [System.Web.Http.ActionNameAttribute("init")]
    [System.Web.Http.HttpPostAttribute]
    public string init([System.Web.Http.FromBodyAttribute] object jsonString);
}
}

RouteMapper.cs

using DotNetNuke.Web.Api;
using GdPicture14.WEB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;

namespace DocumentViewer
{
public class RouterMapper : IServiceRouteMapper
{
    public void RegisterRoutes(IMapRoute mapRouteManager)
    {
        mapRouteManager.MapHttpRoute(
        "DocumentViewer",
        "default",
        "{controller}/{action}",
        new string[] { "DocumentViewer" });
    }
}
}

1 个答案:

答案 0 :(得分:0)

我的VehiDataCollector module

中的DNN模块中有一个API调用示例

您需要提供a route mapper

 public void RegisterRoutes(IMapRoute mapRouteManager)
    {
        mapRouteManager.MapHttpRoute("VehiDataCollector","Default", "{controller}.ashx/{action}",
                                 new[] { "Christoc.Modules.VehiDataCollector.Services" });

        //mapRouteManager.MapHttpRoute("MyServices", "default", "{controller}/{action}", new {"MyServices"});
    }

然后像@Mickers的a controller that inherits from DnnApiController在评论中指出

 public class VehiDataCollectorController : DnnApiController
    {
        //URL to get the list of vehicles

        [HttpGet]
        //[DnnAuthorize()]
        //TODO: make it so we can call without ModuleId to get a list of vehicles
        [AllowAnonymous]
        public HttpResponseMessage GetVehicles()
        {
            try
            {
                var mc = new ModuleController();
                var mi = mc.GetModuleByDefinition(0, "VehiDataCollector"); 
//TODO: assuming PortalId=0 if moduleid =0 
                return GetVehicles(mi.ModuleID); 
            }
            catch (Exception exc)
            {
                DnnLog.Error(exc); //todo: obsolete
                return Request.CreateResponse(HttpStatusCode.BadRequest, "Module Not On A Page, or No Vehicles Exist"); //todo: probably should localize that?
            }
        }
    }