Flex 3 - how to support HTTP Authentication URLRequest?

前端 未结 9 1374
清酒与你
清酒与你 2020-11-29 03:21

I have a Flex file upload script that uses URLRequest to upload files to a server. I want to add support for http authentication (password protected directories on the serve

9条回答
  •  时光取名叫无心
    2020-11-29 03:36

    Here is a work-around when using ASP.Net based in part on the work here.

    I built a component that dynamically writes Flex objects to the page so they can be used in UpdatePanels. Message me if you want they code. To solve the above problem in pages where authentication cookies will need to be sent by URLRequest, I add the values in as flashVars.

    This code only works in my object, but you get the idea

    Dictionary flashVars = new Dictionary();     
    flashVars.Add("auth", Request.Cookies["LOOKINGGLASSFORMSAUTH"].Value);
    flashVars.Add("sess", Request.Cookies["ASP.NET_SessionId"].Value);
    myFlexObject.SetFlashVars(flashVars);
    

    Then in the Flex Object, check for the params

    if (Application.application.parameters.sess != null)
        sendVars.sess= Application.application.parameters.sess;
    if (Application.application.parameters.auth != null)
        sendVars.au= Application.application.parameters.auth;
    
    request.data = sendVars;
    request.url = url;
    request.method = URLRequestMethod.POST;
    

    Finally stuff the cookies in on global.asax BeginRequest

    if (Request.RequestType=="POST" && Request.Path.EndsWith("upload.aspx"))
    {
        try
        {
            string session_param_name = "sess";
            string session_cookie_name = "ASP.NET_SESSIONID";
            string session_value = Request.Form[session_param_name]; // ?? Request.QueryString[session_param_name];
            if (session_value != null) { UpdateCookie(session_cookie_name, session_value); }
        }
        catch (Exception) { }
    
        try
        {
            string auth_param_name = "au";
            string auth_cookie_name = FormsAuthentication.FormsCookieName;
            string auth_value = Request.Form[auth_param_name];// ?? Request.QueryString[auth_param_name];
    
            if (auth_value != null) { UpdateCookie(auth_cookie_name, auth_value); }
        }
        catch (Exception) { }   
    
    }
    

    Hope this help someone avoid the 6 hours I just spent addressing this. Adobe has closed the issue as unresolvable, so this was my last resort.

提交回复
热议问题