有人在 DNN 9.9 版本中实现了 DotNetNuke.Abstractions.Portals.IPortalAliasInfo.HttpAlias 吗?
Has anyone implemented DotNetNuke.Abstractions.Portals.IPortalAliasInfo.HttpAlias in DNN version 9.9?
我最近将我的 DNN 版本从 7.3.4 升级到了 9.9。当我编译我的解决方案时,我收到以下警告:
[Obsolete("已在 9.7.2 中弃用。计划在 v11.0.0 中删除,请改用 DotNetNuke.Abstractions.Portals.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.Abstractions.Portals.IPortalAliasInfo.HttpAlias 吗?如果是这样,能否请您提供一个示例?
谢谢。
您将通过 IPortalAliasService.GetPortalAlias
访问 IPortalAliasInfo
我不知道你的确切上下文,但让我们假设一个 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;
}
}
}
}
如果这不是你的上下文,你只需要调整如何做依赖注入部分,但其余的原则是一样的...
我最近将我的 DNN 版本从 7.3.4 升级到了 9.9。当我编译我的解决方案时,我收到以下警告:
[Obsolete("已在 9.7.2 中弃用。计划在 v11.0.0 中删除,请改用 DotNetNuke.Abstractions.Portals.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.Abstractions.Portals.IPortalAliasInfo.HttpAlias 吗?如果是这样,能否请您提供一个示例?
谢谢。
您将通过 IPortalAliasService.GetPortalAlias
访问 IPortalAliasInfo我不知道你的确切上下文,但让我们假设一个 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;
}
}
}
}
如果这不是你的上下文,你只需要调整如何做依赖注入部分,但其余的原则是一样的...