• 获取token之后,再调用匿名方法


    js获取token
    
    
    bpm.api.beginDownload = function (filePath, fileName) {
        var url = "/Home/GetToken";
        $$.getJSON(url, {}, function (data) {
            if (data.IsSuc) {
                var url = "/Home/Download?dirRelativePath=" + filePath + "&token=" + data.Token + "&fileName=" + fileName;
                window.location = url;
                //window.open(url, "_blank");
            }
        });
    }
     public static Hashtable htTokens = Hashtable.Synchronized(new Hashtable());
            public ActionResult GetToken()
            {
                var token = Guid.NewGuid();
                htTokens.Add(token, Tool.GetCurrentUser());
                return Json(new { IsSuc = true, Token = token.ToString() }, JsonRequestBehavior.AllowGet);
            }
            /// <summary>
            /// 暂时无用
            /// </summary>
            /// <param name="dirRelativePath"></param>
            /// <param name="fileName"></param>
            /// <returns></returns>
            [AllowAnonymous]
            public ActionResult OldDownload(string dirRelativePath, string fileName)
            {
                string token = Request.QueryString["token"];
                if (htTokens != null && !string.IsNullOrEmpty(token) && htTokens.Contains(Guid.Parse(token)))
                {
                    string uploadPath = System.Configuration.ConfigurationManager.AppSettings["BPMAttachments"];
                    string dirAbsolutePath = uploadPath + dirRelativePath;
    
                    if (!System.IO.File.Exists(dirAbsolutePath))
                    {
                        return Content("提示:文件在磁盘上不存在");
                    }
                    htTokens.Remove(token);
                    //HttpContext.Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
                    //return File(dirAbsolutePath, "application/octet-stream");
                    var contentType = MimeMapping.GetMimeMapping(fileName);
                    HttpContext.Response.AddHeader("content-disposition", "inline;filename=" + fileName);
                    return File(dirAbsolutePath, contentType);
                }
                else
                {
                    return Content("提示:没有权限");
                }
            }
  • 相关阅读:
    FMDB使用的一点心得:数据库创建、制表、查询等以及image转换成二进制nsdata保存到数据库中
    Java基本数据类型
    hashtable C++实现
    Libgdx中TextButton的一些思考
    [伯努利数] poj 1707 Sum of powers
    POJ 3020:Antenna Placement(无向二分图的最小路径覆盖)
    flume 读取kafka 数据
    [R] 之 帮助函数
    [python] 之 类编码细节
    [python] 之 装饰器
  • 原文地址:https://www.cnblogs.com/xuguanghui/p/5984509.html
Copyright © 2020-2023  润新知