gpt4 book ai didi

asp.net-mvc - 回发总是返回状态代码 301 永久移动

转载 作者:可可西里 更新时间:2023-11-01 16:54:12 24 4
gpt4 key购买 nike

任何类型的回发,Ajax 或标准 M​​VC 表单提交,都会返回状态代码 301。似乎操作或 Controller 是什么都没有区别。将浏览器从 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>

Controller :

public class XXXController : AsyncController
{
[HttpPost]
public ActionResult YYY()
{
return null; // ====== NEVER REACHES HERE
}
}

标题

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“永久移动”,而不是执行 Action 方法?

最佳答案

解决方案是在回发 URL 的末尾放置一个正斜杠:

url: '/XXX/yyy'   ==> 301 Moved Permanently
url: '/XXX/yyy/' ==> 200 OK

非常尴尬地浪费了一天的工作。

关于asp.net-mvc - 回发总是返回状态代码 301 永久移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47418710/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com