有人实现过DotNetNuke吗.摘要.门户网站.IPortalAliasInfo.DNN 9.9版本中的HttpAli



我最近将DNN版本从7.3.4升级到9.9。当我编译我的解决方案时,我会收到以下警告:

[作废(9.7.2中已弃用。计划在v11.0.0中删除,请使用DotNetNuke。摘要。门户网站。IPortalAliasInfo。取而代之的是HttpAlias"(]

我试图实现IPortalAlaiasInfo,但一直没有成功。我查看了DNN的启动文件,看到了以下服务:

public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<WebFormsModuleControlFactory>();
services.AddSingleton<Html5ModuleControlFactory>();
services.AddSingleton<ReflectedModuleControlFactory>();
services.AddSingleton<IDnnContext, DotNetNukeContext>();
services.AddScoped<IEventLogger, EventLogController>();
services.AddScoped<IEventLogConfigService, EventLogController>();
services.AddScoped<IEventLogService, EventLogController>();
services.AddTransient((IServiceProvider x) => ServiceLocator<IPortalController, PortalController>.Instance);
services.AddScoped<IHostSettingsService, HostController>();
services.AddScoped<INavigationManager, NavigationManager>();
services.AddScoped<ISerializationManager, SerializationManager>();
services.AddScoped<IApplicationInfo, DotNetNuke.Application.Application>();
services.AddScoped<IApplicationStatusInfo, ApplicationStatusInfo>();
services.AddScoped<IPortalAliasService, PortalAliasController>();
}

我看不到对接口IPortalAliasInfo的引用。

有人知道如何访问DotNetNuke吗。摘要。门户网站。IPortalAliasInfo。HttpAlias?如果是的话,你能提供一个例子吗?

谢谢。

您可以通过IPortalAliasService访问IPortalAlialsInfo。GetPortalAlias

我不知道你的确切上下文,但让我们假设一个WebApi端点,它看起来像这样:

using DotNetNuke.Abstractions.Portals;
using DotNetNuke.Web.Api;
using System;
using System.Linq;
using System.Web.Http;
namespace My.Namespace
{
public class MyController : DnnApiController
{
private readonly IPortalAliasService portalAliasService;
public MyController(IPortalAliasService portalAliasService)
{
this.portalAliasService = portalAliasService;
}
[HttpGet]
[AllowAnonymous]
public IHttpActionResult GetPrimaryPortalAlias()
{
try
{
var primaryPortalAlias = this.portalAliasService.GetPortalAliasesByPortalId(this.PortalSettings.PortalId)
.First(p => p.IsPrimary);
return this.Ok(primaryPortalAlias.HttpAlias);
}
catch (Exception)
{
var message = "Something went wrong";
return this.InternalServerError(new Exception(message));
throw;
}
}
}
}

如果这不是你的上下文,你只需要调整如何进行依赖注入部分,但其余的都是相同的原则。。。

最新更新