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";
}
uploadify Cookie 验证登入上传问题的更多相关文章
- form验证及图片上传
form验证及图片上传 这一节增加推荐图书的提交和删除功能,来学习node的form提交以及node的图片上传功能.开始之前需要源码同学可以先在git上fork:https://github.com/ ...
- django设置并获取cookie/session,文件上传,ajax接收文件,post/get请求及跨域请求等的方法
django设置并获取cookie/session,文件上传,ajax接收文件等的方法: views.py文件: from django.shortcuts import render,HttpRes ...
- JQUery利用Uploadify插件实现文件异步上传(十一)
一:简介: Uploadify是JQuery的一个上传插件,实现的效果非常好,带进度显示 ,且Ajax异步,能一次性上传多个文件,功能强大,使用简单 1.支持单文件或多文件上传,可控制并发上传的文件数 ...
- Spring学习笔记2——表单数据验证、文件上传
在上一章节Spring学习笔记1——IOC: 尽量使用注解以及java代码中,已经搭建了项目的整体框架,介绍了IOC以及mybatis.第二节主要介绍SpringMVC中的表单数据验证以及文件上传. ...
- django 使用其自带的验证系统 进行用户名有效性验证 登录状态验证 登入操作 登出操作
from django.shortcuts import render, redirect from django.contrib.auth import authenticate, login, l ...
- 【技术博客】Postman接口测试教程 - 环境、附加验证、文件上传测试
Postman接口测试教程 - 环境.附加验证.文件上传测试 v1.0 作者:ZBW 前言 继利用Postman和Jmeter进行接口性能测试之后,我们发现Postman作为一款入门容易的工具,其内置 ...
- uploadify 一款优秀的上传插件
官方网址:www.uploadify.com 使用文档:www.uploadify.com/documentation 效果如下 注释以及文件结构已经过本人修改,和官方的有些出入. index.php ...
- Uploadify 结合 Web API 2 上传问题
最近使用jQuery.Uploadify和Web API配合来做上传,碰到问题,还木有办法解决,记录一下: 环境:jQuery 1.10.2,Uploadify 3.2.1,SWFObject 2.2 ...
- Nodejs之MEAN栈开发(四)---- form验证及图片上传
这一节增加推荐图书的提交和删除功能,来学习node的form提交以及node的图片上传功能.开始之前需要源码同学可以先在git上fork:https://github.com/stoneniqiu/R ...
随机推荐
- IIS7 禁止目录运行脚本
早晨看博客说有人被黑了:http://www.cnblogs.com/sanshi/p/3150639.html 看回复建议禁用上传目录的脚本运行权限 在IIS6上还是比较容易的,直接右键--属性,把 ...
- Django中model层详解
#!/usr/bin/env python# _*_ coding:utf-8 _*_ from django.db import models class UserType(models.Model ...
- cookie实现刷新不变化树形菜单
通过设置cookie来保存树形菜单的状态,在页面加载时重新读取cookie来设置菜单. 菜单的HTML结构: <div class="treemenu"> <ul ...
- 【AtCoder】AGC016
A - Shrinking 用每个字母模拟一下就行 #include <bits/stdc++.h> #define fi first #define se second #define ...
- You have new mail in /var/spool/mail/root消除提示的方法
有时在进入系统的时候经常提示You have new mail in /var/spool/mail/root 你觉得烦人---解决方法: 修改系统配置文件/etc/profile,告诉系统不要去检查 ...
- http--tomcat--memcached配置
两个tomcat节点:172.16.100.7(tomcatA.magedu.com),172.16.100.8(tomcatB.magedu.com) 两个memcached节点:172.16.10 ...
- Python学习(三十一)—— Django之路由系统
转载自:http://www.cnblogs.com/liwenzhou/p/8271147.html Django的路由系统 Django 1.11版本 URLConf官方文档 URL配置(URLc ...
- 伪分布式hbase数据迁移汇总
https://www.jianshu.com/p/990bb550be3b hbase0.94.11(hadoop为1.1.2,此电脑ip为172.19.32.128)向hbase1.1.2 (ha ...
- day12 函数的使用方法:初识迭代器和生成器
生成器和迭代器比装饰器简单多了... 这是老师的博客地址: http://www.cnblogs.com/Eva-J/articles/7213953.html 前情回顾: #装饰器: # 在不修改一 ...
- 使用 PySide2 开发 Maya 插件系列二:继承 uic 转换出来的 py 文件中的类 Ui_Form
使用 PySide2 开发 Maya 插件系列二:继承 uic 转换出来的 py 文件中的类 Ui_Form 开发环境: Wing IDE 6.1 步骤1: 打开 Wing IDE,创建一个新的 pr ...