为什么 MVC 是无状态的 - 如何解释? [英] Why is MVC stateless - How to explain?

查看:32
本文介绍了为什么 MVC 是无状态的 - 如何解释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在向我的学生解释 ASP.NET MVC 的概念时

While explaining concepts of ASP.NET MVC to my students

MVC 是无状态的.它建立在另一个无状态的之上协议 - HTTP 和 HTTPS

MVC is stateless. It is built on top of another stateless protocol - HTTP and HTTPS

但是一位学生打断并问道,

But one student interrupted and asked,

你说 MVC 是无状态的

You tell that the MVC is stateless

无状态协议从不关心响应是否来自服务器.但是,在 ASP.NET MVC 框架中,您发出请求并等待对于响应.既然你在等待响应,它应该被调用作为有状态的服务.你怎么把它称为无状态服务那么?

Stateless protocol never cares if the response comes back or not from the server. But, in ASP.NET MVC framework, you make a request and wait for the response. Since you wait for the response, it should be called as a stateful service. How come you are calling it a stateless service then?

我真的被困住了,不知道该怎么回答这个问题.

I really got stuck up and wondered what to answer to this question.

有什么想法吗?

推荐答案

MVC 不是无状态的,HTTP 是.

MVC is not stateless, HTTP is.

HTTP 是无状态的并不意味着它是一劳永逸的.客户端确实在等待响应.它是无状态的,因为两个连续的请求没有任何关系.

HTTP being stateless doesn't mean it is fire and forget. The client does wait for the response. It is stateless in the sense that two successive requests have no relation whatsoever.

状态可以使用会话来模拟,例如使用 cookie.

State can be emulated using sessions, for example using cookies.

这篇关于为什么 MVC 是无状态的 - 如何解释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆