2011-11-18 2 views
1

내가 만든 사이트에서 플래시 업 로더를 사용합니다. 큰 파일을 서버에 업로드해야합니다. 문제는이 업 로더가 플래시를 사용한다는 것입니다. 데이터를 제출하면 쿠키가 서버로 다시 전송되지 않으므로 사용자를 확인할 수 없으며 실패하게됩니다. 어쨌든 강제로 쿠키를 서버로 되돌려 보낼 수 있습니까? 이것이 가능하지 않은 경우 쿠키를 다시 보내는 다른 구성 요소와 함께 데이터를 업로드하는 다른 방법이 있습니까?asp.net mvc 3 플래시 업 로더가 쿠키를 무시합니다 (대체?)

답변

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); 
    } 
} 

덧글에있는 Link 다음에 더 도움이 될 것입니다.

+0

은 모든 결과를 확인하는 외부 보안 meganism이없는 경우 작동합니다. – Patrick

+0

당신이 의미하는 것을 얻지 못합니다. – DanielB

+0

특정 쿠키에 대한 모든 요청을 확인하는 ID 서버를 사용합니다. 해당 쿠키가 없으면 연결을 종료합니다. – Patrick