MVC中的内置对象(Built in objects in MVC)

关于mvc中的内置对象,有6个,分别为Request、Response、Session、Cookie、Application、Server

1、Request:请求

Request服务器接受客户端数据的Request.QueryString get请求Request.Form post请求Request.PostRequest.MapPath()将虚拟路径转换成物理路径(SaveAs)Request.Files Post请求的文件(文件上传)

2、Response:响应

Response.Write向客户端输出内容Response.Redirect重定向

3、Session:会话

每一个都是独立的,不能共享

Session 会话 数据保存在服务器中 存储少量重要数据的比如账号Session是一个键值对Session的存活时间 20minSession销毁 Abandon/Clear

4、Cookie:客户端数据

具有时效性

清除cookie的特定值,使用过期的方式

5、Application:当前网站对象

public ActionResult ApplicationData() { HttpContext.Application[“user”] = “123”; return Content(“”); } public ActionResult ApplicationGet() { return Content(HttpContext.Application[“user”].ToString()); }

ApplicationData()是存储是数据

ApplicationGet()是获取数据

session是每个人独立的,而Application是整个项目共有的

6、Server:服务器对象

public ActionResult SaverDemo() { Server.Transfer(path: “/WebForm1.aspx”); return Content(“”); } public ActionResult ShowDemo() { return Content(“这是内容”); }

路径不变,内容发生改变(在挡前网站内WebForm1.aspx),不能转发外站

————————

There are 6 built-in objects in MVC: request, response, session, cookie, application and server

1. Request: request

The request server accepts the request.querystring get request.form post request request. Postrequest. Mappath() of the client data, converts the virtual path to the physical path (SaveAs) request.files post requested file (file upload)

2. Response: response

Response.write output content to the client response.redirect redirection

3. Session: session

Each is independent and cannot be shared

Session session data is stored in the server. For example, a small amount of important data is stored in the server. Session is a key value. The lifetime of session is 20min. Session destroys abandon / clear

4. Cookies: client data

Timeliness

Clear the specific value of the cookie and use the expired method

5. Application: current site object

public ActionResult ApplicationData() { HttpContext.Application[“user”] = “123”; return Content(“”); } public ActionResult ApplicationGet() { return Content(HttpContext.Application[“user”].ToString()); }

Applicationdata() is the stored data

Applicationget() is to get data

Session is independent of everyone, and application is common to the whole project

6. Server: server object

public ActionResult SaverDemo() { Server.Transfer(path: “/WebForm1.aspx”); return Content(“”); } public ActionResult ShowDemo() { return Content(“这是内容”); }

The path remains unchanged, and the content changes (webform1. ASPX in the front website). It cannot be forwarded to other websites