Web API调用从DNN站点返回404

问题描述 投票:0回答:1

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

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

UPDATE

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" });
    }
}
}
c# dotnetnuke
1个回答
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?
            }
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.