MVC中的内置对象

MVC中的内置对象
    • request 请求
    • response 响应
    • headers 头
    • session 会话
    • cookie 客户端数据
    • application 当前网站对象
    • server 服务器对象

    • Request
    • ① Request.QueryString : get:请求,通过QueryString的方式 www.baidu,com?name=12&id=10发起

      ② Request.Form: post请求, 通过form的方式发起

      <form action="Home/PostData" method="post">
          <input type="text" name="loginname" />
          <button>提交</button> 
      

      ③ Request.MapPath() 虚拟路径转换为物理路径
      ④Reques.Files() Post请求的文件(文件上传)
      <客户端代码>

       <form action="Home/PostFile" method="post" enctype="multipart/form-data">
              <input type="file" name="file" />
              <button>提交</button>
          </form>
      

      //服务器代码

        public ActionResult PostFile()
              {
              //虚拟路径转为绝对路径
                  Request.Files["file"].SaveAs(Request.MapPath("~/Files/") + Request.Files["file"].FileName);
                  return Content(Request.Files["file"].FileName + " is saved");
              }
      
    • Repose 响应 服务器向客户端响应
    • ①Response.Write()向客户端写入内容 ②Response.Redirect() 重定向
    • headers Response.Headers["hi"] = "hello word"; //向客户端发送头 return Content(Request.Headers["token"]); //获取客户端的头
    • Session 会话 所有客户端自己的数据存储空间,存储在服务器,存储少量的数据,账号 Session 是键值对 Session存活时间20min Session 销毁 Clear()/Abandon()
    • Cookie 客户端存储 向客户端添加Cookie
      Response.Cookies.Add(new HttpCookie("username")
      {
               Value = "abc",
                Expires = DateTime.Now.AddHours(1)
       });
      
    • 获取客户端的Cookie
      Request.Cookies[“username”].Value.ToString()
      删除客户端的Cookiex
      Response.Cookies.Add(new HttpCookie(“username”)
      {
      Expires = DateTime.Now.AddDays(-1)
      });

    • Application
    • 全局,键值对形式,整个网站所共有的
      Set:
      HttpContext.Application[“user”] = “123”;

      Get:
      HttpContext.Application[“user”].ToString();

    • Server 常用的方法 Server.MapPath()获取物理路径 和 Request.MapPath() Sever.Transfer() 转发 ,,,
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值