Search code examples
asp.net-web-apidotnetnuke2sxc

Api Not Found in Dnn v8 Site


We have a Dnn site we are retiring and replacing. We decided that an easy way to export the client data we needed was to re-use a 2sxc Api tool we already had built for another project. So we installed the latest version of 2sxc (11.12.1), everything seems to work fine. Added an app, got all the files in place and started testing.

No matter what we do, we get 404 errors on the api.

Is there an additional config or something that we need to do to get Dnn v8 to allow the URLs to get routed?

We've tried the long and short versions with no luck. We moved the setup to a Dnn v9.08.01 and it works as expected.

/api/2sxc/app/appname/api/public/hello

/DesktopModules/2sxc/api/app/appname/api/public/hello

We even switched from our code to the demo in the 2sxc basic WebApi Examples and none of the possible path variations (that work in Dnn 9) work in Dnn 8.

Any idea what we are missing?

>>> Continued May (the) 4th (be with you) 2021

Upgraded 2sxc to 11.22.0 LTS

Continued to try various things. Renamed the file (and Class) from api/PublicController.cs to api/AppExtController.cs. Tested using the new 2sxc Api tools. Still no luck.

Finally got on the server and tried it again in the browser local and it finally spit out a detailed - surprising, to me - error:

<ExceptionMessage>An error occurred when trying to create a controller of type 'AppExtController'. Make sure that the controller has a parameterless public constructor.</ExceptionMessage>

<InnerException>
<Message>An error has occurred.</Message>
<ExceptionMessage>Unable to resolve AppExtController IsResolutionCall from Container with ambient ScopeContext DnnSharp.DryIoc.AsyncExecutionFlowScopeContext with Scope {Name=~WebRequestScopeName} with Rules with {SelectLastRegisteredFactory} with FactorySelector=SelectLastRegisteredFactory with Made={FactoryMethod=ConstructorWithResolvableArguments, PropertiesAndFields=<custom>, ParameterSelector=<custom>} Where no service registrations found and no dynamic registrations found in 0 of Rules.DynamicServiceProviders and nothing found in 1 of Rules.UnknownServiceResolvers</ExceptionMessage>

<ExceptionType>DnnSharp.DryIoc.ContainerException</ExceptionType>

<StackTrace> at DnnSharp.DryIoc.Throw.It(Int32 error, Object arg0, Object arg1, Object arg2, Object arg3) at DnnSharp.DryIoc.Container.TryThrowUnableToResolve(Request request) at DnnSharp.DryIoc.Container.DnnSharp.DryIoc.IContainer.ResolveFactory(Request request) at DnnSharp.DryIoc.Container.ResolveAndCacheFactoryDelegate(Type serviceType, IfUnresolved ifUnresolved) at DnnSharp.Common2.IoC.WebApi.DnnSharpDependencyScope.GetService(Type serviceType) at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator) at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)</StackTrace>
</InnerException>

The key thing to note above if you missed it, is the exception is being thrown by DnnSharp.DryIoc.

I realize that might mean it is not a 2sxc problem. But I do have DnnSharp's ActionForm installed. I am not aware of any API options or settings.

Is there some way to sort out why routing or handling gets used? Where should I be looking to fix this?

Additionally, below you mentioned "wrong configuration in DNN (primary domain missing..." - can you provide some more details on what I need to check in relation to that? I did check and the DefaultPortalAlias matches the settings for the site. It is the only portal (0) and there are no languages.

Site Settings, Site Behavior, Site Aliases has the same domain as Primary and the Site Alias Mapping Mode is Redirect.

Servers/System Info/Web, Site Url shows the same domain also.

Are any of those related or in play? They all seem to align.


Solution

  • We ended up removing ActionForm from the site and the API started working as expected. So it was related to dependency injection conflicts. I could have done a paid upgrade to ActionForm to get a more recent version that fixed it (we were using v5.1.54), but instead there was only 1 contact form, so we replaced it with something else, removed AF and the issue vanished.