Check this
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
}
/**
* Noroute action
*
* @return \Magento\Framework\Controller\ResultInterface\Magento\Backend\Model\View\Result\Page
*/
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->setStatusHeader(403404, '1.1', 'Forbidden''Not Found');
//$resultPage->setHeader('Status', '404 File not found');
$resultPage->addHandle('adminhtml_denied''adminhtml_noroute');
return $resultPage;
}