1

I am trying to generate the following url, in the adminhtml area:

$this->url->getUrl('adminhtml/system_config/edit', ['section' => 'mysection']);
// where $this->url is an instance of \Magento\Framework\UrlInterface

and the url is being generated correctly.

The only thing is that another security key is being generated as part of the url (I'm getting "Invalid security or form key. Please refresh the page." on the next page after I click the generated link).

How can I preserve the current key?

  • 1
    If you are creating admin URL link, try using Magento\Backend\Model\UrlInterface class. – Jaimin Sutariya Jul 24 at 16:53
  • 1
    this solved my problem. you should add this comment as an answer and I'll be happy to approve it. – Radu Jul 25 at 7:35
0

The issue with your approach is that you are using Magento\Framework\UrlInterface to create admin url. Magento has a separate Interface defined for Backend urls.

Please use Magento\Backend\Model\UrlInterface class to generate your URL with correct secret key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.