zoukankan      html  css  js  c++  java
  • asp.net mvc之ActionResult

    Web服务器接收到一个客户端请求以后,会对请求予以相应,而这个响应是通过Response来控制的,

    但是在asp.net mvc 里,这部分的工作是由ActionResult来完成的,

    ActionResult是一个抽象类,所以具体的工作还是由很多个子类来完成,

    具体的子类有

    EmptyResult,

    ContentResult

    (通过Content,ContentEncoding,ContentType 分别设置返回的内容,字符编码格式以及媒体类型),

    FileResult(FileContentResult,FilePathResult,FileStreamResult),

    <p>Use this area to provide additional information.</p>
    <a href="@Url.Action("ImagePath1", new  { id="1" })">下载</a>
    
    <img src="@Url.Action("ImagePath1", new  { id="1" })" />
    
    <img src="@Url.Action("ImagePath", new  { id="1" })" />
    
    <img src="@Url.Action("ImageContent", new  { id="1" })" />
    
    <img src="@Url.Action("ImageStream", new  { id="1" })" />
    
            public ActionResult ImagePath(string id)
            {
                string path = Server.MapPath("/images/" + id + ".jpeg");
                return File(path, "image/jpeg");
            }
    
            public ActionResult ImagePath1(string id)
            {
                string path = Server.MapPath("/images/" + id + ".jpeg");
                return File(path, "image/jpeg", "下载");
            }
    
    
            public ActionResult ImageContent(string id)
            {
                string path = Server.MapPath("/images/" + id + ".jpeg");
                byte[] heByte = null;
                using (FileStream fsRead = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    int fsLen = (int)fsRead.Length;
                    heByte = new byte[fsLen];
                    int r = fsRead.Read(heByte, 0, heByte.Length);
                }
                return File(heByte, "image/jpeg");
            }
            public ActionResult ImageStream(string id)
            {
                string path = Server.MapPath("/images/" + id + ".jpeg");
                FileStream fsRead = new FileStream(path, FileMode.Open, FileAccess.Read);
    
                return File(fsRead, "image/jpeg");
    
            }
    

    JavaScriptResult,

    返回一段js,且媒体类型是application/x-javascript,

    JsonResult,

    返回Json数据,默认ContentType为Application/json.

    HttpStatusCodeResult,

    具体是通过设置response的StatusCode和StatusDescription来完成输出

    RedirectResult,RedirectToRouteResult,

    内部是通过Response的Redirect/RedirectPermanent来完成操作,

    redirectresult具有两个属性permanent和URL,URL可以是绝对的地址也可以是相对地址,permanent决定了重定向是暂时的还是永久的重定向,

    两种重定向的不同点事搜索引擎会根据永久重定向来更新自己的索引,

    RedirectToRouteResult较RediretResult多了一步根据路由计算出来这个URL值,

    所以RedirectToRouteResult没有URL属性,却包含RouteName以及RouteValues属性,

    ViewResult.

     ViewResult是一个特殊的ActionResult,但也是最复杂的一个

  • 相关阅读:
    Android播放器实现视频窗口实时放大缩小功能
    Spydroid还是大牛直播内置RTSP服务SDK
    安卓端/iOS端如何播放4K分辨率的RTMP/RTSP流
    mingw64+msys2下使用cmake问题
    h264, h265 和 libvpx 比较(h264/avc, hevc 和vp9比较)
    直播协议的选择:RTMP vs. HLS
    如何推送和播放RTMP H265流 (RTMP HEVC)
    如何支持RTSP播放H.265(HEVC)流
    如何实现RTSP推送H.264、RTSP推送H.265(hevc)
    rtmp/rtsp/hls公网测试地址
  • 原文地址:https://www.cnblogs.com/LittleFeiHu/p/7258167.html
Copyright © 2011-2022 走看看