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 ...
随机推荐
- No module named 'PyQt5.sip'
使用pyinstaller打包python文件为windows可执行程序可能遇到的问题 pyinstaller yourprogram.py打包的程序双击打开一闪而过,提示上面标题的错误 把pycom ...
- python——集合
在python中,字典的亲戚就是集合,集合就是无映射关系的字典,花括号并不是字典的特权.如下面程序所示: >>> num = {} >>> type(num) &l ...
- 邮件系统之Postfix与Dovecot
电子邮件系统 电子邮件系统基于邮件协议来完成电子邮件的传输,常见的邮件协议有: 简单邮件传输协议(Simple Mail Transfer Protocol,SMTP):用于发送和中转发出的电子邮件, ...
- Android面试收集录17 Android进程优先级
在安卓系统中:当系统内存不足时,Android系统将根据进程的优先级选择杀死一些不太重要的进程,优先级低的先杀死.进程优先级从高到低如下. 前台进程 处于正在与用户交互的activity 与前台act ...
- Android 用Chrome浏览器打开url 自定义样式
1.效果预览 1.1.真实效果就是从某一个APP,打开一个url,跳转到谷歌浏览器,返回之后,又回到之前的APP 1.2.说明一下条件 1.手机上必须要安装谷歌浏览器 2.手机上的默认浏览器 ...
- Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable
编译的时候出现这个,我从svn download下来的代码,运行就报这个错. 当时我还无知的大吼,怎么可能没有配置java_home, 运行了java -version 都显示出来1.8了. 后来,让 ...
- android gesture检测
1.关于on<TouchEvent>的返回值 a return value of true from the individual on<TouchEvent> methods ...
- 剑指Offer - 九度1348 - 数组中的逆序对
剑指Offer - 九度1348 - 数组中的逆序对2014-01-30 23:19 题目描述: 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个 ...
- 《Cracking the Coding Interview》——第8章:面向对象设计——题目6
2014-04-23 22:57 题目:实现一个数据结构来表示拼图游戏中的碎片. 解法:一个拼图块儿有四条边,每边只有凹凸平三种情况,当两块碎片拼接的时候,分为四个方向进行,块儿上的图案肯定也是判断是 ...
- Remote使用出现的问题及解决办法
最近尝试跟着虫师的OP模式所写的bbs代码,应用自己的项目尝试修改,在第一步Remote启动Firefox上便出错,当前selenium2.53,firefox47.1,selenium server ...