在了解 MVC 概念时,我了解到在“GET”操作中包含更改服务器对象状态(数据库更新等)的代码不是一个好习惯。 “缓存返回数据”已作为原因给出。
有人可以解释一下吗?
提前致谢!
最佳答案
这是 HTTP 标准。 GET 动词应该是幂等且安全的。
9.1.1 Safe Methods
Implementors should be aware that the software represents the user in their interactions over the Internet, and should be careful to allow the user to be aware of any actions they might take which may have an unexpected significance to themselves or others.
In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.
Naturally, it is not possible to ensure that the server does not generate side-effects as a result of performing a GET request; in fact, some dynamic resources consider that a feature. The important distinction here is that the user did not request the side-effects, so therefore cannot be held accountable for them.
关于c# - MVC 获取与发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19413166/