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

Posted hope

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取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("提示:没有权限");
            }
        }

 

以上是关于获取token之后,再调用匿名方法的主要内容,如果未能解决你的问题,请参考以下文章

小程序的登录授权

Django上自建一个token校验机制

java 匿名对象,内部类,修饰符,代码块

java学习中,匿名函数构造方法构造代码块构造方法中调用构造方法(java 学习中的小记录)

你是如何获取 access_token 的,JAVA 代码,我获取不到

没有接口怎么请求token