MVC内置函数

----HTML页

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
 
<body>
    <form action="/Dome/PostDate" method="post">
 
        <input type="text" name="loginname" />
        <button>提交</button>
    </form>
    <form action="/Dome/FileDate" method="post" enctype="multipart/form-data">
        <input type="file" name="file" />
        <button>提交</button>
    </form>
    <form action="/Dome/SessionDate" method="post">
 
        <input type="text" name="user" />
        <button>提交</button>
    </form>
</body>
</html>

----控制器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
 
namespace 项目.Controllers
{
    public class DomeController : Controller
    {
        // GET: Dome
        public ActionResult Index()
        {
            //内置对象  Request  Response   Session   Cooking      Application    Server
            //          请求     响应        会话     客户端数据    当前网站对象   服务器对象
 
            //Request 服务器接收客户端数据
            //Request.QueryString get 请求!
            //Request.Form post 请求!
            //request.MapPath()作用是将虚拟路径转化为物理路径
            // Request.Files["file"] 获取的是POSt请求的文件,俗称文件上传
 
            //headers
            return Content($"{Request.QueryString["name"]}-{Request.QueryString["age"]}");
             //http://localhost:62036/?name=asdf&age=12  用于接收客户端传来的数据
 
        }
        public ActionResult PostDate()
        {
            return Content(Request.Form["loginname"]);
        }
        public ActionResult FileDate()
        {
            //saveas 方法需要物理路径
            //request.MapPath()作用是将虚拟路径转化为物理路径
            Request.Files["file"].SaveAs(filename: Request.MapPath("~/uploads/" + Request.Files["file"].FileName));
            return Content("ok");
        }
 
        public ActionResult ReqponseDate()  //响应是服务器给客户端
        {
            //   Response.Write 向客户输出内容
            //   Response.Redirect 重定向
            //Response.Write(s:"hello word");  
            //http://localhost:62036/Dome/ReqponseDate 案例
            Response.Redirect("http://www.baidu.com//");
            return Content("");
        }
        public ActionResult RequestHeader()
        {
            Request.Headers["hollow"] = "world";
            return Content(Request.Headers["token"]);  //请求头
        }
        public ActionResult SessionDate() //所有人自己的存储空间
        {
            //Sission 会话,数据保存在服务器中(一般用来存储少量重要数据(用户名))
            //Sission 是一个键值对
            //Session 的存活时间为20分钟
            //Session 销毁 Abandon/Clear
            Session["user"] = Request.Form["user"];
            return Content("会话中使用的数据是"+Session["user"]);
        }
        public ActionResult GetSession()
        {
            return Content("当前会话的数据是"+Session["user"]);
        }
        public ActionResult ClearSession()
        {
            Session.Clear();   //清除Sission
            Session.Abandon(); //销毁Sission
            return Content("Sission已经清除");
        }
 
        //Cookie  客户端输出的数据一概认为是不安全的数据
 
        public ActionResult CookieSave()
        {
            //时效性
            Response.Cookies.Add(new HttpCookie(name: "token")//服务器告诉客户端cookie需要保存7天
            {
                Value = "asdfasdfasd",
                Expires = DateTime.Now.AddDays(7)
            });
            return Content("ok");
        }
        public ActionResult CookieGet()
        {
            return Content(Request.Cookies["token"].Value); //客户端请求获取到cookie的值
            //http://localhost:62036/dome/CookieGet
        }
        public ActionResult CookieClear()
        {
 
            //清除cookie 值,使用过期的方式
            Response.Cookies.Add(new HttpCookie(name: "token")
            {
                Expires = DateTime.Now.AddDays(-1)
            });
            return Content("OK");
        }
        public ActionResult ApplicationDate()  // Application  整个服务器共用存
        {
            HttpContext.Application["user"] = "adsfasdf";
            return Content("");
        }
        public ActionResult ApplicationGet() //Application  整个服务器共用 取
        {
            HttpContext.Application["user"] = "adsfasdf";
            return Content(HttpContext.Application["user"].ToString());
        }
        public ActionResult ServerDate()  //服务器对象的应用
        {
            // Server.Transfer 路径不变,内容变了,但是只能转发当前网址内
            //   Server.MapPath(); 虚拟路径转化为物理路径
            //   Response.Redirect 用于重定向可定向任意路径
            Server.Transfer(path:"`/~~~");
            return Content("辛苦了");
        }
    
    }
}

MVC内置对象的更多相关文章

  1. JSP的执行原理、JSP的内置对象、四大作用域解析、MVC模式理解>从零开始学JAVA系列

    目录 JSP的执行原理.JSP的内置对象.四大作用域解析.MVC模式理解 JSP的执行原理 这里拿一个小例子来解析JSP是如何被访问到的 首先将该项目部署到tomcat,并且通过tomcat启动 通过 ...

  2. [.Net Core] 简单使用 Mvc 内置的 Ioc(续)

    简单使用 Mvc 内置的 Ioc(续) 本文基于 .NET Core 2.0. 上一章<[.Net Core] 简单使用 Mvc 内置的 Ioc>已经对日常 Mvc 中的 Ioc 的简单用 ...

  3. JSP运行过程 JSP脚本 静态动态包含 jsp指令 jsp内置对象jsp四大作用域 jsp动作元素 EL表达式 JSTL 设计模式 JSP开发模式 EL内置对象

    Day38 JSP JSP的运行过程具体如下: (1)客户端发出请求,请求访问JSP文件. (2)JSP容器先将JSP文件转换成一个Java源文件(Java Servlet源程序),在转换过程中,如果 ...

  4. MVC路由 路由的三种扩展 替换MVC内置的Handler

    Global.asax 是 程序入口文件 路由配置   为什么localhost:8088/Home/Index/1 能返问到我们写的 会去掉前缀跟端口号  变成Home/Index/1 用这个跟路由 ...

  5. SpringBoot系列三:SpringBoot基本概念(统一父 pom 管理、SpringBoot 代码测试、启动注解分析、配置访问路径、使用内置对象、项目打包发布)

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.了解SpringBoot的基本概念 2.具体内容 在之前所建立的 SpringBoot 项目只是根据官方文档实现的一个基础程 ...

  6. Asp.Net六大内置对象

    前面学习mvc管道处理模型的时候,我们晓的HttpContext是贯穿全文的一个对象,在HttpRuntime产生,现在我们所谓的Asp.Net六大内置对象,其实就是HttpContext的属性.具体 ...

  7. Spring,SpringMVC,MyBatis,Hibernate,Servlet的生命周期,jsp有哪些内置对象,Tomcat,Cookie和Session的作用以及区别,oracle,MYSQL等面试题总结

    1. 什么是Spring,谈谈你对Spring的理解 Spring是我们JAVA开发人员在搭建后台时选用的一个轻量级的开源框架,Spring框架目前也是功能丰富,十分优秀企业级采用最多的一个框架. S ...

  8. java web学习总结(二十五) -------------------JSP中的九个内置对象

    一.JSP运行原理 每个JSP 页面在第一次被访问时,WEB容器都会把请求交给JSP引擎(即一个Java程序)去处理.JSP引擎先将JSP翻译成一个_jspServlet(实质上也是一个servlet ...

  9. javaScript的内置对象

    javaScript 有11种内置对象: Array . String .Date .Math . Boolean .Number . Function .Global .Error . RegExp ...

  10. ASP.NET的六大内置对象

    ASP.NET 六大内置对象(System.Web.UI.Page类): 1.Response 2.Request 3.Server 4.Application 5.Session 6.Cooki R ...

随机推荐

  1. Python的入门学习Day 10~13——form”夜曲编程“

    Day 10 time:2021.8.7. ​ 今天本来打算学习时发现手机应该拿去充电了,再上完J课程之后发现时间确实只留到了晚上呢 .但幸好,以我多天的敲代码的牢固根基(哈哈哈),我最终还是弥补回来 ...

  2. hdu 4283You Are the One

    The TV shows such as You Are the One has been very popular. In order to meet the need of boys who ar ...

  3. vue3 门户网站搭建6-wangeditor

    门户网站的新闻.公告等文章,内容可配置,故引入 wagneditor 1.安装: npm i wangeditor 2.方便调用,抽成组件: <template> <div ref= ...

  4. python requests 模拟登录

    转载: https://blog.csdn.net/m0_59485658/article/details/128115786

  5. 【uboot 】uboot通过tftp下载内核

    1.开发板uboot,虚拟机能相互ping通 2.ubuntu搭建好tftp服务器,设置好文件夹,放置好文件 sudo apt install tftpd-hpa  //安装服务程序 sudo sys ...

  6. Delphi 新语法:匿名函数

    这里的新语法一般指Delphi7不支持的语法. 对于比较简单实现,不需要复用,开发者更喜欢在使用时,原地声明,而没有必要单独声明并实现这个方法. 通过关键字reference来定义一个匿名函数. 下面 ...

  7. 3DMAX安装失败怎么办?安装3DMAX失败提示错误怎么解决?

    3DMAX安装失败怎么办?安装3DMAX失败提示错误怎么解决?有很多同学想把3DMAX卸载后重新安装,但是发现3DMAX安装到一半就失败了或者显示3DMAX已安装或者安装未完成,大多数情况下其实是3D ...

  8. easypoi多sheet导出

    以前一直接触的是单sheet导出,这次的需求换成了多sheet导出,算是一个难点所以得记录一下 底层关键的代码就是: private static void defaultExport(List< ...

  9. 初始化centos环境脚本

    #! /bin/bashecho "java环境初始化开始"#功能描述: Centos8.5系统自动初始化脚本#自动配置:IP地址\Yum源\docer\docker-compos ...

  10. VS code 安装后gdb调试无法显示STL内容的问题

    bar {...} std::_Vector_base<TSample<MyTraits>, std::allocator<TSample<MyTraits> &g ...