Session is different if flash uploads photo to the aspx page

随声附和 提交于 2020-03-23 17:38:33

问题


I have a aspx called user-photo-upload.aspx and another aspx called get-photo.aspx. I set the Session["PhotoId"] in the page_load method of user-photo-upload.aspx.

If I visit the user-photo-upload.aspx through the browser normally, the session can be retrieved in get-photo.aspx. But if the flash uploads photo to the user-photo-upload.aspx page, I can't get the Session["PhotoId"] in get-photo.aspx.

I discover that the Session ID is different when visiting the page using browser normally or by flash. I don't know why flash uses another session.

What should I do?


回答1:


The Flash plugin acts as a separate client, so both the browser and the plugin receiving individual session IDs is the expected behavior.

You will have to work around this by setting the original session ID as a variable in the Flash movie, either as a FlashVar or via JavaScript, then sending it as a GET parameter to the server along with the first request issued, and replacing the new ID created for the Flash client with the one that was given to the server.

This question relates to the same problem in Java, perhaps it can help you to solve your problem.




回答2:


We had the same problem with a Flash Uploader. This is how we solved it...

(1) We added a new parameter session_id to the client side init code of the Flash Uploader:

<script type="text/javascript"> 
   var swfu<%=RandomId %>;
   $(document).ready(function() {
      swfu<%=RandomId %> = new SWFUpload({
    // Backend Settings
    upload_url: "./picupload.aspx",
    post_params : {                    
         "PictureCategory" : "<%= EncryptedPictureCategory() %>",
         "picture_id": "<%= EncryptedPictureId() %>",
         "session_id": "<%= HttpContext.Current.Session.SessionID %>"
     },
     // *snip* ...
</script>

(2) We altered our Session_Start method in Global.asax.cs to accept Session IDs from the request:

protected void Session_Start(Object sender, EventArgs e)
{
    if (Request["session_id"] != null)
    {
        bool isRedirected, isCookieAdded;
        string oldSessionId = Request["session_id"];
        SessionIDManager manager = new SessionIDManager();
        manager.RemoveSessionID(HttpContext.Current);
        manager.SaveSessionID(HttpContext.Current, oldSessionId, out isRedirected, out isCookieAdded);
    }
    else
    {
        Response.Redirect(LoginPagePath);
    }
}


来源:https://stackoverflow.com/questions/5341607/session-is-different-if-flash-uploads-photo-to-the-aspx-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!