This documentation is for the old version. Go to the latest Upload Suite docs

Maintaining Sessions and Authentication in ASP.NET

If you are going to utilize Image Uploader Flash in non-Internet Explorer browsers (Firefox, Safari, and etc.), you should take care about keeping your session and authentication cookies saved if they are used. The fact is that Image Uploader Flash does not send cookies in output requests in non-Internet Explorer browsers by default and, therefore, session and authentication tickets are lost during the upload. To work around this problem you can employ special facilities provided either by Image Uploader Flash ASP.NET or Image Uploader Flash JavaScript. Let us consider how to use them.

Using Image Uploader Flash ASP.NET

If you use Image Uploader Flash ASP.NET, session and authentication information will be automatically passed to the upload request. If you are unfamiliar with Image Uploader Flash ASP.NET, please, see the Quick Start with Image Uploader Flash ASP.NET topic.

To restore passed cookies server-side you need to add UploaderModule module to your web.config, like follows:

XML
<configuration>
   <!-- other sections -->
   <system.web>
        <!-- other sections -->
        <httpModules>
            <!-- other modules -->
            <add name="UploaderModule" type="Aurigma.ImageUploaderFlash.UploaderModule"/>
        </httpModules>
        <!-- other sections -->
   </system.web>
   <!-- other sections -->
   <system.webServer>
        <!-- other sections -->
        <modules>
            <!-- other modules -->
            <add name="UploaderModule" type="Aurigma.ImageUploaderFlash.UploaderModule"/>
        </modules>
        <!-- other sections -->
   </system.webServer>
   <!-- other sections -->
</configuration>

In order to configure the ASP.NET authentication scheme you should add the authentication section to your web.config, for example, like it is shown in the following example:

XML
<authentication mode="Forms">
  <forms name="AurigmaUser" loginUrl="~/Login.aspx" defaultUrl="~/Default.aspx"
         protection="All" path="/" timeout="525600"/>
</authentication>

Using Image Uploader Flash JavaScript API

If you prefer not to use Image Uploader Flash ASP.NET, then you should add cookies to the upload request manually via the Image Uploader Flash JavaScript. To do this, use the metadata.addCustomField(String, String, Boolean) method which accepts cookie in the following format: "cookieName=cookieValue". The most convenient place to call this method is the BeforeUpload event handler, because this event fires when the upload is about to be started.

JavaScript
function beforeUploadHandler(){
    var fu = $au.imageUploaderFlash('Uploader1');
    fu.metadata().addCustomField('ASP.NET_SessionId','<%=Page.Session.SessionID%>',true);
    fu.metadata().addCustomField('<%=FormsAuthentication.FormsCookieName%>',
        '<%=Request.Cookies[FormsAuthentication.FormsCookieName].Value %>',true);
};

var fu = $au.imageUploaderFlash({
    id: 'Uploader1',
    events: { beforeUpload: beforeUploadHandler}
});

fu.writeHtml();

The previous example uses ASP.NET_SessionId as session cookie name, because it is default name for this cookie in ASP.NET. However, you may determine the session cookie name programatically, as follows:

C#
((System.Web.Configuration.SessionStateSection)ConfigurationManager.GetSection("system.web/sessionState")).CookieName

To restore passed cookies server-side you need to add UploaderModule module to your web.config, like follows:

XML
<configuration>
   <!-- other sections -->
   <system.web>
        <!-- other sections -->
        <httpModules>
            <!-- other modules -->
            <add name="UploaderModule" type="Aurigma.ImageUploaderFlash.UploaderModule"/>
        </httpModules>
        <!-- other sections -->
   </system.web>
   <!-- other sections -->
   <system.webServer>
        <!-- other sections -->
        <modules>
            <!-- other modules -->
            <add name="UploaderModule" type="Aurigma.ImageUploaderFlash.UploaderModule"/>
        </modules>
        <!-- other sections -->
   </system.webServer>
   <!-- other sections -->
</configuration>

See Also

Reference

Manual