1

作成したサイトで Flash アップローダーを使用しています。大きなファイルをサーバーにアップロードする必要があります。問題は、このアップローダがフラッシュを使用していることです。データを送信すると、Cookie がサーバーに送り返されないため、ユーザーを確認できず、これは失敗します。クッキーを強制的にサーバーに送り返す方法はありますか? これが不可能な場合は、Cookie を送り返す他のコンポーネントを使用してデータをアップロードする別の方法があります。

4

1 に答える 1

0

この問題について議論しているサイトがいくつかあります。解決策は、フラッシュ内の別のポスト変数を使用して、認証情報を手動で 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);
    }
}

コメントのリンクをたどると、さらに役立ちます。

于 2011-11-18T11:56:51.163 に答える