回发总是 returns 状态码 301 永久移动
Postback always returns status code 301 Moved Permanently
任何类型的回发,Ajax 或标准 MVC 表单提交,都会返回状态代码 301。操作或控制器是什么似乎没有区别。将浏览器从 Chrome 更改为 Firefox 没有帮助。
<script>
$('.zzz').click(function (e)
{
e.preventDefault();
e.stopPropagation();
$.ajax({
url: '/XXX/yyy',
data: { test: "hello" },
type: "post",
success: function () { alert("success"); },
error: function () { alert("error"); }
});
});
</script>
控制器:
public class XXXController : AsyncController
{
[HttpPost]
public ActionResult YYY()
{
return null; // ====== NEVER REACHES HERE
}
}
Headers
Request URL:http://localhost:47038/xxx/yyy
Request Method:POST
Status Code:301 Moved Permanently
Remote Address:[::1]:47038
Referrer Policy:no-referrer-when-downgrade
Response Headers
=================
Access-Control-Allow-Origin:*
Content-Length:154
Content-Type:text/html; charset=UTF-8
Date:Tue, 21 Nov 2017 16:02:23 GMT
Location:http://localhost:47038/xxx/yyy/
Server:Microsoft-IIS/10.0
X-Frame-Options:SAMEORIGIN
X-Powered-By:ASP.NET
X-SourceFiles:=?UTF-8?B?QzpcdmF1bHRccHJpbnRlcnBpeG12Y3VpXFByaW50ZXJQaXhNdmNVSVxYWFhcWVlZ?=
Request Headers
================
view source
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-GB,en-US;q=0.9,en;q=0.8
Connection:keep-alive
Content-Length:10
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:ASP.NET_SessionId=rargvavdg0reeuhqvqkznsaj; MachineToken=a2fec363-6318-4ec3-8d2c-0eee116fc778; __RequestVerificationToken=80gj5joNWUpBjgjOsxkV0SkDwhrX3fNbzYTZrTaUGpJXlIEY7nyguehSDpz525JKyNfjlI5Two-poQs1dC2jw0kWnpvnK74iz4X3KV5MtSI1
Host:localhost:47038
Origin:http://localhost:47038
Referer:http://localhost:47038/xxx/Index/?product=puzzle
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Data
==========
test:hello
GET 请求工作正常,只是重定向了 POST。
为什么返回 301 "Moved Permanently",而不是执行 Action 方法?
解决方案是在回发的末尾加上正斜杠 URL:
url: '/XXX/yyy' ==> 301 Moved Permanently
url: '/XXX/yyy/' ==> 200 OK
浪费了一天的工作,真是令人尴尬。
任何类型的回发,Ajax 或标准 MVC 表单提交,都会返回状态代码 301。操作或控制器是什么似乎没有区别。将浏览器从 Chrome 更改为 Firefox 没有帮助。
<script>
$('.zzz').click(function (e)
{
e.preventDefault();
e.stopPropagation();
$.ajax({
url: '/XXX/yyy',
data: { test: "hello" },
type: "post",
success: function () { alert("success"); },
error: function () { alert("error"); }
});
});
</script>
控制器:
public class XXXController : AsyncController
{
[HttpPost]
public ActionResult YYY()
{
return null; // ====== NEVER REACHES HERE
}
}
Headers
Request URL:http://localhost:47038/xxx/yyy
Request Method:POST
Status Code:301 Moved Permanently
Remote Address:[::1]:47038
Referrer Policy:no-referrer-when-downgrade
Response Headers
=================
Access-Control-Allow-Origin:*
Content-Length:154
Content-Type:text/html; charset=UTF-8
Date:Tue, 21 Nov 2017 16:02:23 GMT
Location:http://localhost:47038/xxx/yyy/
Server:Microsoft-IIS/10.0
X-Frame-Options:SAMEORIGIN
X-Powered-By:ASP.NET
X-SourceFiles:=?UTF-8?B?QzpcdmF1bHRccHJpbnRlcnBpeG12Y3VpXFByaW50ZXJQaXhNdmNVSVxYWFhcWVlZ?=
Request Headers
================
view source
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-GB,en-US;q=0.9,en;q=0.8
Connection:keep-alive
Content-Length:10
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:ASP.NET_SessionId=rargvavdg0reeuhqvqkznsaj; MachineToken=a2fec363-6318-4ec3-8d2c-0eee116fc778; __RequestVerificationToken=80gj5joNWUpBjgjOsxkV0SkDwhrX3fNbzYTZrTaUGpJXlIEY7nyguehSDpz525JKyNfjlI5Two-poQs1dC2jw0kWnpvnK74iz4X3KV5MtSI1
Host:localhost:47038
Origin:http://localhost:47038
Referer:http://localhost:47038/xxx/Index/?product=puzzle
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Data
==========
test:hello
GET 请求工作正常,只是重定向了 POST。
为什么返回 301 "Moved Permanently",而不是执行 Action 方法?
解决方案是在回发的末尾加上正斜杠 URL:
url: '/XXX/yyy' ==> 301 Moved Permanently
url: '/XXX/yyy/' ==> 200 OK
浪费了一天的工作,真是令人尴尬。