Yii2 Generate URL 405 What's going on?

Source: Internet
Author: User
When using Yii, the following conditions occur,
Use on the template page ">退出后台
After parsing the page generated code URL address is localhost/yii2/backend/index.php?r=site/logout, the address is right, when the visit appears as follows:
Method Not Allowed (#405) Method Not Allowed. This url can only handle the following request methods: POST. The above error occurred while the Web server was processing your request. Please contact us if you think this is a server error. Thank you.

Excuse me, why does it appear 405? Where is the wrong configuration? No routing is configured inside the configuration file
It is possible to find the foreground through Firebug, and it is a post submission. And the URL-generated access is wrong? Help

Reply content:

When using Yii, the following conditions occur,
Use on the template page">退出后台
After parsing the page generated code URL address is localhost/yii2/backend/index.php?r=site/logout, the address is right, when the visit appears as follows:
Method Not Allowed (#405) Method Not Allowed. This url can only handle the following request methods: POST. The above error occurred while the Web server was processing your request. Please contact us if you think this is a server error. Thank you.

Excuse me, why does it appear 405? Where is the wrong configuration? No routing is configured inside the configuration file
It is possible to find the foreground through Firebug, and it is a post submission. And the URL-generated access is wrong? Help

The verbs of site/logout This action must be configured, and it is clear that this action only accepts requests sent through post!
So you check if the behaviors under Sitecontroller is configured.

'verb' => [    'class' => VerbFilter::className(),    'actions' => [        'logout' => ['post'],    ],],

If get access is allowed, then it can be changed to:

'verb' => [    'class' => VerbFilter::className(),    'actions' => [        'logout' => ['get'], //当然可以是是 ['get', 'post'],同时支持POST和GET两种方式访问    ],],
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.