jquery.uploadify不支持MVC的Authorize
原文发布时间为:2011-10-18 —— 来源于本人的百度文章 [由搬家工具导入]
为什么jquery.uploadify不支持MVC的Authorize呢,因为flash的cookie跟服务端的不一样。
http://stackoverflow.com/questions/1729179/uploadify-session-and-authentication-with-asp-net-mvc
There was not "properly" an issue with my code. The usage of the plugin was generally correct but there was an issue with the authentication mechanism.
As everybody can find on the internet the flash plugin does not share the authentication cookie with the server-side code and this was the reason behind the usage of the "scriptData" section inside my code that contained the Authentication Cookie.
The problem was related to the fact that the controller was decorated with the [Authorize] attribute and this was never letting the request reach its destination.
The solution, found with the help of another user on the uploadify forum, is to write a customized version of the AuthorizeAttribute like you can see in the following code.
/// <summary>
/// A custom version of the <see cref="AuthorizeAttribute"/> that supports working
/// around a cookie/session bug in Flash.
/// </summary>
/// <remarks>
/// Details of the bug and workaround can be found on this blog:
/// http://geekswithblogs.net/apopovsky/archive/2009/05/06/working-around-flash-cookie-bug-in-asp.net-mvc.aspx
/// </remarks>
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method,Inherited=true,AllowMultiple=true)]
publicclassTokenizedAuthorizeAttribute:AuthorizeAttribute
{
/// <summary>
/// The key to the authentication token that should be submitted somewhere in the request.
/// </summary>
privateconststring TOKEN_KEY ="AuthenticationToken";
/// <summary>
/// This changes the behavior of AuthorizeCore so that it will only authorize
/// users if a valid token is submitted with the request.
/// </summary>
/// <param name="httpContext"></param>
/// <returns></returns>
protectedoverrideboolAuthorizeCore(System.Web.HttpContextBase httpContext ){
string token = httpContext.Request.Params[TOKEN_KEY];
if( token !=null){
FormsAuthenticationTicket ticket =FormsAuthentication.Decrypt( token );
if( ticket !=null){
FormsIdentity identity =newFormsIdentity( ticket );
string[] roles =System.Web.Security.Roles.GetRolesForUser( identity.Name);
GenericPrincipal principal =newGenericPrincipal( identity, roles );
httpContext.User= principal;
}
}
returnbase.AuthorizeCore( httpContext );
}
}
http://www.uploadify.com/download/
jquery.uploadify不支持MVC的Authorize的更多相关文章
- jquery.uploadify上传文件配置详解(asp.net mvc)
页面源码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" c ...
- asp.net mvc 2.o 中使用JQuery.uploadify
From:http://www.cnblogs.com/strugglesMen/archive/2011/07/01/2095916.html 官方网站http://www.uploadify.co ...
- MVC 4 结合jquery.uploadify 上传实例
前言:由于今天公司源代码服务瘫痪,没法编写代码,利用这个有限的时间,做了一个小小的 基于MVC的图片上传demo,貌似近些年来MVC十分火爆,相关的demo也数不胜数,小弟就在这里打着MVC的旗子,狐 ...
- jquery.uploadify+spring mvc实现上传图片
一.前端页面 1.下载jquery.uploadify 去uploadify官网(http://www.uploadify.com/download/)下载压缩包,解压后放在如下路径: 2.html结 ...
- MVC中使用jquery uploadify上传图片报302错误
使用jquery uploadify上传图片报302错误研究了半天,发现我上传的action中有根据session判断用户是否登录,如果没有登录就跳到登陆页,所以就出现了302跳转错误.原来更新了fl ...
- jquery.uploadify文件上传组件
1.jquery.uploadify简介 在ASP.NET中上传的控件有很多,比如.NET自带的FileUpload,以及SWFUpload,Uploadify等等,尤其后面两个控件的用户体验比较好, ...
- jQuery.uploadify文件上传组件实例讲解
1.jquery.uploadify简介 在ASP.NET中上传的控件有很多,比如.NET自带的FileUpload,以及SWFUpload,Uploadify等等,尤其后面两个控件的用户体验比较好, ...
- 解决jQuery uploadify在非IE核心浏览器下无法上传
之前上传了一个通过Flash实现多文件上传,但是在IE正常运行,FireFox 不能正常上传.经过反复研究学习,之所以firefox和360浏览器无法正常运行,是因为FireFox.chrome.36 ...
- 使用jQuery Uploadify在ASP.NET 上传附件
Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.Uploadify官方网址:http://www.uploadify.com/,在MVC中使用的方法可以参考 jQuer ...
随机推荐
- anaconda+jupyter notebook 安装配置
安装Anaconda 从清华大学开源软件镜像站选择合适自己的版本 wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda ...
- 谈一谈如何远程访问MySQL(腾讯云,云主机)
连接MySQL (其他的sql 基本相同套路) 腾讯云不管怎么设置端口和MySQL权限以及监听端口就是不能连接? 远程访问MySQL数据库的几个关键点 端口设置 数据库权限设置 数据库的监听端口设置 ...
- Hive学习路线图
- Python全栈day 06
Python全栈day 06 一.数据类型补充完整 1. 列表(list) 反转reverse list1 = [1,2,3,4,5,6,7,8,9] list1.reverse() print(li ...
- C语言数组篇(四)二维数组
二维数组声明: ][] ={{,,},{,,}; //两行 三列 二维数组在声明的时候可以不写行,但一定要写列 ] = {{,},{,,},{}}; //未声明的地方自动补零 二维 ...
- 笔记-scrapy与twisted
笔记-scrapy与twisted Scrapy使用了Twisted作为框架,Twisted有些特殊的地方是它是事件驱动的,并且比较适合异步的代码. 在任何情况下,都不要写阻塞的代码.阻塞的代码包括: ...
- talent-aio源码阅读小记(二)
我们上一篇提到了talent-aio的四类Task:DecodeRunnable.HandlerRunnable.SendRunnable.CloseRunnable,并且分析了这些task的基类Ab ...
- javaScript对SEO的影响
在两大搜索引擎阵营中,大量实践证明百度对JAVASCRIP的处理很不理想而GOOGLE的处理要好一些. 网页中出现大量的JavaScript会给搜索引擎爬行增加难度.其主要影响有以下几点: 1.干 ...
- printf("%d \n", -1 < sizeof(int) ) Implicit conversion
; printf( < sizeof(int) ); 结果输出: 0 在写程序时,经常对于比较很随意,特别是类型不同时,然而这带来的错误也是意想不到,却理所当然. 剖析: sizeof(int) ...
- 《1024伐木累》-BUG的通用解决办法
本周月侠出场,一番侠骨柔情,或许你会为丽姐担忧,或许你也很想知道,发现了一个不该发现的秘密,月侠的未来究竟会怎样,但是一切都只是一个开头,伴随故事成长,伴随故事了解时事,尤其是IT圈子里的事儿,或许真 ...