简体   繁体   中英

Why is action result cached?

I have an action that generates a password reset link and emails it to the user

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);
}

The first time I call the action from the browser, I get an HTTP 200 response (and hit my breakpoint in the action).

The second time I call the action from the browser, I get an HTTP 304 response indicating that the content is unchanged.

There are no [OutputCache] attributes anywhere in the source file (not on the class or the action).

What is causing the web server to decide that the content is unchanged and return the HTTP 304?

I'm aware of a work-around

https://stackoverflow.com/a/18620970/141172

I'm interested in understanding the root cause for the HTTP 304 response.

Update

Headers on first request:

Request Headers

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 Headers

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

NOTE: I changed localhost to local in the above because StackOverflow does not allow links containing localhost to be posted :-)

The browser is Internet Explorer 10.

IE caches ajax responses by default, you need to explicitly tell it not to do any ajax caching by setting your ajax object's cache property to false.

Browsers such as Chrome automatically append a random token to your request to make it unique.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM