1
我在我创建了一个网站使用Flash上传。我需要将大文件上传到服务器。问题是这个上传器使用闪存。当提交数据的cookie不会发送回服务器,所以为此我无法验证用户,这将失败。有没有办法强制将cookie发送回服务器?如果这是不可能的,是否有其他的方式将数据与回送饼干的其他组件上传。asp.net MVC 3 Flash上传忽略饼干(二选一?)
我在我创建了一个网站使用Flash上传。我需要将大文件上传到服务器。问题是这个上传器使用闪存。当提交数据的cookie不会发送回服务器,所以为此我无法验证用户,这将失败。有没有办法强制将cookie发送回服务器?如果这是不可能的,是否有其他的方式将数据与回送饼干的其他组件上传。asp.net MVC 3 Flash上传忽略饼干(二选一?)
有几个网站,这个问题进行了讨论。解决方案是,手动将授权信息通过flash中的另一个post变量传回给MVC。我找到的实现是TokenizedAuthorizeAttribute
。
/// <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);
}
}
继评论中的Link将帮助您进一步。
会工作,如果没有一个外部安全meganism检查每个结果。 – Patrick
不明白你的意思。 – DanielB
我使用的检查everyrequest特定cookie中的身份服务器。如果该cookie不存在,它将终止连接。 – Patrick