I have recently upgraded my DNN version from 7.3.4 to 9.9. When I compile my solution, I get the following warning:
[Obsolete("Deprecated in 9.7.2. Scheduled for removal in v11.0.0, use DotNetNuke.Abstractions.Portals.IPortalAliasInfo.HttpAlias instead.")]
I tried to implement IPortalAlaiasInfo, but I have been unsuccessful. I looked at the Startup file for DNN and see the following services:
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>();
}
I do not see a reference to interface IPortalAliasInfo.
Does any one know how to access DotNetNuke.Abstractions.Portals.IPortalAliasInfo.HttpAlias? If so, can you please be so kind to provide an example?
Thank you.
You would access IPortalAliasInfo through IPortalAliasService.GetPortalAlias
I don't know your exact context but let's assume a WebApi endpoint, it would look something like this:
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;
}
}
}
}
If that's not your context you just have to adjust on how to do the dependency injection part, but the rest is the same principle...