ControlPath 等效于 DotNetNuke DnnApiController ActiveModule

ControlPath equivalent from DotNetNuke DnnApiController ActiveModule

有没有办法从 DnnApiController 获取 ActiveModule 的模块根文件夹(DesktopModules 下的文件夹)?

PortalModuleBase 中,我将使用 ControlPath 属性 来访问我要查找的同一根文件夹。

从 API 来看,它并没有出现,你应该知道它的路径,因为你在你的模块内部,唯一的问题是你是否在子门户内部需要前缀,你应该能够得到。我只是使用 Server.ResolveClientUrl() 来获取它。

正如@MitchelSellers 指出的那样,它似乎不在 API 中,因此您必须自己弄清楚。 由于 API 为我们提供了 ActiveModule,这是一个 ModuleInfo,这可能是获得它的最佳方式。

如果您的模块使用非常标准的一致命名,那么下面的 "best guess" 方法应该工作得很好

public static string ControlPath(ModuleInfo mi, bool isMvc = false)
{
    return isMvc
        ? $"/DesktopModules/MVC/{mi.DesktopModule.FolderName}"
        : $"/DesktopModules/{mi.DesktopModule.FolderName}";
}

另一种方法是查看我们模块的 ModuleDefinitions 并抓住第一个 ModuleControl 并查看它的 ControlSrc 以查看它的路径。

public static string ControlPath(ModuleInfo mi)
{
    var mdi = mi.DesktopModule.ModuleDefinitions.First().Value;
    var mci = mdi.ModuleControls.First().Value; // 1st ModuleControl

    return Path.GetDirectoryName(mci.ControlSrc);
}

第二种方法非常混乱(且未经测试),但应该为您提供安装控件的实际文件夹路径,而不是上面的其他最佳猜测方法。