Skip to content

Magento 2.4.6. Error message: Invalid security or form key. Please refresh the page

On Magento 2.4.6 I am trying to create an option from the admin panel to navigate to a newly created page.

enter image description here

When trying to do this I get an error:

Invalid security or form key. Please refresh the page.

enter image description here

Could you please help me what I am doing wrong?

My code:

appcodeDevControllerAdminhtmlControllerIndex.php:

namespace DevControllerAdminhtmlController;


use MagentoBackendAppAction;
use MagentoBackendAppActionContext;
use MagentoFrameworkViewResultPageFactory;

class Index extends Action
{
    protected $resultPageFactory;

    public function __construct(Context $context, PageFactory $resultPageFactory)
    {
        parent::__construct($context);
        $this->resultPageFactory = $resultPageFactory;
    }

    public function execute()
    {
        $resultPage = $this->resultPageFactory->create();
        $resultPage->getConfig()->getTitle()->prepend(__('Dev Module Page'));
        return $resultPage;
    }
}

appcodeDevRestApietcadminhtmlmenu.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
    <menu>
        <add id="Dev_RestApi::dev_module" title="Dev Module" module="Dev_RestApi" sortOrder="10" parent="Magento_Backend::content" resource="Dev_RestApi::dev_module"/>
        <add id="Dev_RestApi::dev_module_PriceInfo_Module" title="PriceInfo_Module" module="Dev_RestApi" sortOrder="10" parent="Dev_RestApi::dev_module" action="dev/controller/action" resource="Dev_RestApi::dev_module_PriceInfo_Module"/>
    </menu>
</config>

appcodeDevRestApietcadminhtmlroutes.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin">
        <route id="dev" frontName="dev">
            <module name="Dev_RestApi" />
        </route>
    </router>
</config>

appcodeDevRestApietcacl.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
    <acl>
        <resources>
            <resource id="Magento_Backend::admin">
                <resource id="Dev_RestApi::dev" title="Dev Module" sortOrder="10">
                    <resource id="Dev_RestApi::dev_index" title="Dev Index" sortOrder="10" />
                </resource>
            </resource>
        </resources>
    </acl>
</config>