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 ...
随机推荐
- 微信小程序CheckBox选中事件
1.微信小程CheckBox选中问题 <checkbox-group bindchange="checkboxChange" data-index="{{index ...
- js for 循环中有异步函数时,回调函数总是最后一步的值。
原因:for循环执行时不会等待异步函数执行. 解决方法: 1.改为递归函数(暂时不会). 2.构建一个自执行函数传参(匿名函数) 参考::https://www.cnblogs.com/csuwuji ...
- hdoj 1237 模拟
计算器 Problem Description 读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值. Input 测试输入包含若干测试用例,每个测试用例占一行,每行不超过 ...
- jdk1.8源码学习笔记
前言: 前一段时间开始学习了一些基本的数据结构和算法,算是弥补了这方面的知识短板,但是仅仅是对一些算法的了解,目前工作当中也并没有应用到这些,因此希望通过结合实际例子来学习,巩固之前学到的内容,思前想 ...
- Android 游标
静下心来,学一下Android的数据库连接. 1.直接从getReadableDatabase()与getWritableDatabase()入手. --getReadableDatabase( ...
- 计算机指令集CISC与RISC
当接触一新CPU时商家会首先描述它是RISC指令集,这意味着什么,从这个描述你能了解多少CPU特性信息? 复杂指令集计算机(CISC) 长期来,计算机性能的提高往往是通过增加硬件的复杂性来获得.随着集 ...
- centos使用--ssh登陆
1 安装openssh-server yum install openssh-server 2 登录 在配置好ssh后就可以只使用SSH密钥登录而不允许通过密码登录了,方法如下: 修改ssh配置: v ...
- Managing WMI security
TechNet Library TechNet Archive Windows Server 2003 Product Help Windows Server 2003 Product Help Ad ...
- Python3中文教程
搜索 此文档来源自网络 安装 PYTHON❝ Tempora mutantur nos et mutamur in illis. (时光流转,吾等亦随之而变.) ❞ — 古罗马谚语 深入欢迎来到 Py ...
- [网站公告]又拍云API故障造成图片无法上传
大家好,今天早上8:30左右发现又拍云API出现故障,造成图片无法上传,调用图片上传API时出现错误:“The operation has timed out”. 该故障给大家带来了麻烦,望大家谅解! ...