我有一个动作,生成密码重置链接并通过电子邮件发送给用户
public ActionResult SendResetPasswordEmail(string userName)
{
var webUser = LoadUser(userName);
if (webUser != null)
{
var token = WebSecurity.GeneratePasswordResetToken(webUser.UserName);
emailSender.SendPasswordResetEmail(webUser, token, resetAction);
return new HttpStatusCodeResult(HttpStatusCode.OK);
}
return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "No user found with username: " + userName);
}
我第一次从浏览器调用该操作时,得到HTTP 200响应(并在操作中点击我的断点).
我第二次从浏览器调用该操作时,收到HTTP 304响应,指示内容未更改.
源文件中没有[OutputCache]属性(不在类或操作上).
是什么导致Web服务器决定内容未更改并返回HTTP 304?
我知道一个解决方法
https://stackoverflow.com/a/18620970/141172
我有兴趣了解HTTP 304响应的根本原因.
更新
首次请求标题:
请求标题
Request GET /Companies/SendResetPasswordEmail/?userName=ej HTTP/1.1
X-Requested-With XMLHttpRequest
Accept */*
Referer http://local:6797/Companies
Accept-Language en-US
Accept-Encoding gzip, deflate
User-Agent Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)
Host localhost:6797
DNT 1
Connection Keep-Alive
Cookie __RequestVerificationToken=sNOBS6qz32LtnJpLWgHHELhaE44DfIVE1LSMUgjzHjcwsvxlUFa4lOSyA5QeB8keLXYL08Psjg29CRI7W73uHLJy6A81; .ASPXAUTH=DAF8AF47E955F723EE9438866BE1B4BFBF91BA01912EF087824F03581DBCA05A4AECA01373FAF40DF0C4D5C17F17DEFA2F85C1B702988B7E0F750BFE19566FC711C7D6BD81D8F0B0ABD68AF5B3D9BA032286361F; ASP.NET_SessionId=5e2gcvkc2p3rji25z5emyqzd; HelixPlugins1.0=IEPlugin1.0
响应标题
Response HTTP/1.1 200 OK
Server ASP.NET Development Server/11.0.0.0
Date Thu, 03 Apr 2014 23:29:02 GMT
Cache-Control private, s-maxage=0
Content-Length 0
Connection Close
注意:我在上面将localhost更改为local,因为StackOverflow不允许发布包含localhost的链接:-)
浏览器是Internet Explorer 10.
最佳答案 IE默认缓存ajax响应,你需要通过将ajax对象的cache属性设置为false来明确告诉它不要进行任何ajax缓存.
Chrome等浏览器会自动在您的请求中添加随机令牌,以使其唯一.