Magento 2 Custom Admin Action Redirected to Dashboard

This happens because 'secret key' is missing when you just type in URL manually. Secret key feature is enabled by default and can be disabled here: Stores => Configuration => Advanced => Admin => Security => Add Secret Key to URLs. Then you should be able to reach your action.


In router.xml file (companyName/customModule/etc/adminhtml/router.xml) For me the solution was to have the route id and frontName have the same value. In your case this would be:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
    <router id="admin">
        <route id="asw_advanved" frontName="asw_advanved">
            <module name="Asw_Sample" before="Magento_Backend"/>
        </route>
    </router>
</config>

Maybe it's better to use that property:

/**
 * Array of actions which can be processed without secret key validation
 *
 * @var array
 */
protected $_publicActions = ['action_name'];