public object DownFile(string filecode)
 {
     if (string.IsNullOrEmpty(filecode))
     {
         HttpContext.Current.Response.Write("参数错误");
         HttpContext.Current.Response.End();
         return null;
     }
     string filepath = StrFormatClass.Decrypt(filecode, ref errmsg);
     if (!string.IsNullOrEmpty(errmsg) || string.IsNullOrEmpty(filepath) || filepath.Length <= 14)
     {
         HttpContext.Current.Response.Write("参数解析错误");
         HttpContext.Current.Response.End();
         return null;
     }
     filepath = filepath.Substring(0, filepath.Length - 14);
     string filename = Models.GlobalParameters.RootFilePath + filepath;
     if (!File.Exists(filename))
     {
         HttpContext.Current.Response.Write("文件不存在");
         HttpContext.Current.Response.End();
         return null;
     }
     string fname = Path.GetFileName(filename);
     //文件名  
     string str = "attachment;filename=" + fname;
     //把文件头输出,此文件头激活文件下载框  
     HttpContext.Current.Response.AppendHeader("Content-Disposition", str);//http报头文件  
     HttpContext.Current.Response.ContentType = "application/octet-stream";
     HttpContext.Current.Response.WriteFile(filename);
     HttpContext.Current.Response.Flush();
     HttpContext.Current.Response.End();
     return null;
 }
Beispiel #2
0
        public UserInfoViewModel Readcookie(ref string errmsg)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies["CIRSUser"];

            if (cookie == null || string.IsNullOrEmpty(cookie.Value))
            {
                errmsg = "未登录";
                return(null);
            }
            string decTicket = StrFormatClass.Decrypt(cookie.Value, ref errmsg);

            if (string.IsNullOrEmpty(decTicket) || !string.IsNullOrEmpty(errmsg))
            {
                errmsg = "解密用户认证数据错误";
                return(null);
            }
            UserInfoViewModel userData;

            try
            {
                userData = JsonConvert.DeserializeObject <UserInfoViewModel>(decTicket);
            }
            catch
            {
                errmsg   = "反序列化错误";
                userData = null;
            }
            return(userData);
        }