asp.net mvc 3 flash上载程序忽略cookie(可选?)

asp.net mvc 3 flash上载程序忽略cookie(可选?),flash,asp.net-mvc-3,cookies,uploader,Flash,Asp.net Mvc 3,Cookies,Uploader,我在我创建的网站中使用flash上传程序。我需要上传大文件到服务器。问题是这个上传程序使用flash。当它提交数据时,cookies不会发送回服务器,因此我无法验证用户,这将失败。是否存在强制将cookie发送回服务器的方法?如果这是不可能的,是否有其他方法使用发送回cookie的其他组件上载数据。有几个站点讨论了这个问题。解决方案是,使用flash中的另一个post变量手动将授权信息传递回MVC。我发现的一个实现是标记化authorizeAttribute /// <summary>

我在我创建的网站中使用flash上传程序。我需要上传大文件到服务器。问题是这个上传程序使用flash。当它提交数据时,cookies不会发送回服务器,因此我无法验证用户,这将失败。是否存在强制将cookie发送回服务器的方法?如果这是不可能的,是否有其他方法使用发送回cookie的其他组件上载数据。

有几个站点讨论了这个问题。解决方案是,使用flash中的另一个post变量手动将授权信息传递回MVC。我发现的一个实现是
标记化authorizeAttribute

/// <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)]
public class TokenizedAuthorizeAttribute : AuthorizeAttribute
{
    /// <summary>
    /// The key to the authentication token that should be submitted somewhere in the request.
    /// </summary>
    private const string 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>
    protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext)
    {
        string token = httpContext.Request.Params[TOKEN_KEY];

        if (token != null)
        {
            FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(token);

            if (ticket != null)
            {
                FormsIdentity identity = new FormsIdentity(ticket);
                string[] roles = System.Web.Security.Roles.GetRolesForUser(identity.Name);
                GenericPrincipal principal = new GenericPrincipal(identity, roles);
                httpContext.User = principal;
            }
        }

        return base.AuthorizeCore(httpContext);
    }
}
//
///支持工作模式的自定义版本
///围绕Flash中的cookie/会话错误。
/// 
/// 
///有关错误和解决方法的详细信息,请访问此博客:
/// http://geekswithblogs.net/apopovsky/archive/2009/05/06/working-around-flash-cookie-bug-in-asp.net-mvc.aspx
/// 
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method,Inherited=true,AllowMultiple=true)]
公共类TokenizeAuthorizeAttribute:AuthorizeAttribute
{
/// 
///应在请求中某处提交的身份验证令牌的密钥。
/// 
私有常量字符串令牌\u KEY=“AuthenticationToken”;
/// 
///这将更改AuthorizeCore的行为,使其仅进行授权
///如果与请求一起提交了有效令牌,则返回用户。
/// 
/// 
/// 
受保护的覆盖bool AuthorizeCore(System.Web.HttpContextBase httpContext)
{
string token=httpContext.Request.Params[token_KEY];
if(令牌!=null)
{
FormsAuthenticationTicket票证=FormsAuthentication.Decrypt(令牌);
如果(票证!=null)
{
表单实体标识=新表单实体(票证);
string[]roles=System.Web.Security.roles.GetRolesForUser(identity.Name);
GenericPrincipal=新的GenericPrincipal(身份、角色);
httpContext.User=principal;
}
}
返回base.AuthorizeCore(httpContext);
}
}

如果没有检查每个结果的外部安全性巨头,那么遵循注释中的将有助于您进一步了解。

将起作用。我使用一个身份服务器来检查特定cookie的everyrequest。如果cookie不在那里,它将终止连接。