Add-on for EPiServer 12 from the scratch

Vote:
 

Hi there,

I'm trying to build a simple Add-on for EPiServer 12 but faced an issue. Well, my add-on is quite simple: only one class-controller.

using Microsoft.AspNetCore.Mvc;

namespace MyEPiModule
{
    public class HelloController : Controller
    {
        [HttpGet]
        public ActionResult Index()
        {
            return new ContentResult { Content = "Hello from my EPiServer module!" };
        }

        [HttpGet]
        public ActionResult Show()
        {
            return new ContentResult { Content = "Show: Hello from my EPiServer module!" };
        }
    }
}

I added one dependency EPiServer.CMS v12.2.1 (I have Foundation site running with the same dependency).

module.config is simple too

<?xml version="1.0" encoding="utf-8"?>
<module loadFromBin="false"
		moduleJsonSerializerType="Net"
		prefferedUiJsonSerializerType="Net"
		clientResourceRelativePath=""
		description="My first EPiServer NET5 Core module"
		tags="EPiServerModulePackage">
  <assemblies>
    <add assembly="MyEPiModule"/>
  </assemblies>

  <routes>
    <route url="{moduleArea}/{controller}/{action}/">
      <defaults>
		<add key="moduleArea" value="MyEPiModule" />
        <add key="controller" value="Hello"/>
		<add key="action" value="Index"/>
      </defaults>
    </route>
  </routes>
</module>

So, I built the module, created a folder /modules/_protected/MyEPiModule, put module.config here, copied MyEPiModule into bin folder (all dlls are here).

But requests /episerver/myepimodule/hello/index and /episerver/myepimodule/hello/show response HTTP404 Not Found.

I checked another OOTB requests:

/EPiServer/EPiServer.OpenIDConnect.UI/OpenIDConnectToken/refreshtokens - HTTP 500
/EPiServer/cms/about/license - redirect
/EPiServer/commerce/catalog - HTTP 200

All of them work fine. Seems like I missed something valuable, but cannot get what the thing I missed.

I developed EPiServer add-on before, for v11. But haven't seen such issues. Could you give me advice how to cause this simple add-on work, please?

#271412
Feb 09, 2022 16:21
Vote:
 

@Mark Hall helped me with the issue

By default the module system does not autodiscover. You can either turn on autodiscover

services.Configure<ProtectedModuleOptions>(x => x.AutoDiscovery = EPiServer.Shell.Configuration.AutoDiscoveryLevel.Modules);

or register manually like

services.Configure<ProtectedModuleOptions>(x =>
            {
                if (!x.Items.Any(x => x.Name.Equals("MyEPiModule")))
                {
                    x.Items.Add(new ModuleDetails
                    {
                        Name = "MyEPiModule"
                    });
                }
            });
#271558
Feb 11, 2022 16:05
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.