Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has anyone implemented DotNetNuke.Abstractions.Portals.IPortalAliasInfo.HttpAlias in DNN version 9.9?

Tags:

c#

dotnetnuke

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.

like image 398
James Avatar asked Sep 03 '25 03:09

James


1 Answers

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...

like image 80
Daniel Valadas Avatar answered Sep 07 '25 20:09

Daniel Valadas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!