## Aurigma Image Uploader 6.1 Dual

# Preserving Sessions and Authentication Tickets Passed in Cookies

- Collapse All Sections
- See Also
- Language Filter ( all languages )

This article describes how to keep session and authentication information saved during upload. In particular, this task is related to passing authentication information by Image Uploader Java in the way used in standard ASP.NET authentication mechanism.

Note

This topic describes a solution for the case when Image Uploader is deployed using embedding scripts. If you use Image Uploader ASP.NET control or Image Uploader PHP library you do not need to perform these instructions.

The thing is that Java version of Image Uploader loses HTTP-only cookies when it uploads files to a server. So you should explicitly pass these cookies to the applet before it starts uploading. To do it you should use the AddCookie() method, which accepts cookie name-value pairs separated with semicolon.

The most convenient place to call this method is the BeforeUpload event handler which fires when the upload is about to be started. The code snippet below demonstrates how to attach authentication and session cookies using this method. Note, this sample is for ASP.NET only.

### JavaScript

    <script type="text/javascript" src="iuembed.js">  </script>
    <script language="javascript">
    function ImageUploader_BeforeUpload(){

    if (iu.getControlType() == "Java")
      getImageUploader("ImageUploader").AddCookie(
        '<%= FormsAuthentication.FormsCookieName %>=<%=Request.Cookies[FormsAuthentication.FormsCookieName].Value %>;' +
        'ASP.NET_SessionId=<%= Request.Cookies["ASP.NET_SessionId"].Value %>');
    }
    var iu = new ImageUploaderWriter("ImageUploader", 770, 500);
    iu.activeXControlEnabled = false;
    iu.javaAppletEnabled = true;

    //For Java applet we specify only directory with JAR files
    iu.javaAppletCodeBase = "./";
    iu.javaAppletCached = false;
    iu.showNonemptyResponse = "off";

    //Other parameters...

    //Configure URL files are uploaded to.
    iu.addParam("Action", "upload.aspx");
    iu.addEventListener("BeforeUpload", "ImageUploader_BeforeUpload");
    iu.writeHtml();
    </script>

For PHP server platform you can use the following sample to preserve PHP session:

### JavaScript

    <script type="text/javascript" src="iuembed.js">  </script>
    <script language="javascript">
    function ImageUploader_BeforeUpload(){

    if (iu.getControlType() == "Java")
        getImageUploader("ImageUploader").AddCookie('PHPSESSID=<?=$_COOKIE["PHPSESSID"]?>');
    }
    var iu = new ImageUploaderWriter("ImageUploader", 770, 500);
    iu.activeXControlEnabled = false;
    iu.javaAppletEnabled = true;

    //For Java applet we specify only directory with JAR files
    iu.javaAppletCodeBase = "./";
    iu.javaAppletCached = false;
    iu.showNonemptyResponse = "off";

    //Other parameters...

    //Configure URL files are uploaded to.
    iu.addParam("Action", "upload.aspx");
    iu.addEventListener("BeforeUpload", "ImageUploader_BeforeUpload");
    iu.writeHtml();
    </script>

Important

The AddCookie() method is implemented in Java part of Image Uploader only, so you should not use it in ActiveX version. To determine the currently loaded version you can use the getControlType() method of the ImageUploaderWriter object.

## See Also

### Reference

- AddCookie() Method
- ResetCookies() Method

### Manual

- Adding Authentication
- Configuring Image Uploader ASP.NET Control
- Configuring Image Uploader PHP