zoukankan      html  css  js  c++  java
  • uploadify Cookie 验证登入上传问题

    上传文件时必须验证是否已登入。

    当用FormsAuthentication做登入,使用FormsAuthentication.FormsCookieName进行验证是否已登入即可。

    <script type="text/javascript">
    var auth = "@(Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty :
    Request.Cookies[FormsAuthentication.FormsCookieName].Value)"; $(window).load( function () { $("#fileuploader").fileUpload({ 'uploader': '/Scripts/uploader.swf', 'cancelImg': '/Images/cancel.png', 'buttonText': 'Select Image', 'script': 'Home/Upload', 'folder': '/uploads', 'fileDesc': 'Image Files', 'fileExt': '*.jpg;*.jpeg;*.gif;*.png', 'multi': true, 'auto': true, scriptData: { token: auth } }); } ); </script> <div id="fileuploader"></div>
            [HttpPost]
            public string Upload(HttpPostedFileBase fileData, string token)
            {
                if (string.IsNullOrEmpty(token))
                {
                    return "noLogin";
                }
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(token);
                if (ticket != null)
                {
                    var identity = new FormsIdentity(ticket);
                    if (identity.IsAuthenticated)
                    {
                        var fileName = this.Server.MapPath("~/uploads/" + System.IO.Path.GetFileName(fileData.FileName));
                        fileData.SaveAs(fileName);
                    }
                }
                return "ok";
            }
  • 相关阅读:
    SCCM2012 R2实战系列之七:软件分发(exe)
    man 手册--nc
    挂载虚拟机磁盘文件
    bond模式详解
    Windows下计算md5值
    man手册--iostat
    mount---挂载文件系统
    Linux-swap分区
    sync---强制将被改变的内容立刻写入磁盘
    vmstat---有关进程、虚存、页面交换空间及 CPU信息
  • 原文地址:https://www.cnblogs.com/ly7454/p/4292628.html
Copyright © 2011-2022 走看看