WebSession ClassAwesomium.NET 1.7.6Awesomium.NET
Represents a session responsible for storing all user-generated data (cookies, cache, authentication, etc.). It can either be purely in-memory or saved to disk.
Inheritance Hierarchy

SystemObject
  Awesomium.CoreViewModel
    Awesomium.CoreNativeViewModel
      Awesomium.CoreWebSession

Namespace: Awesomium.Core
Assembly: Awesomium.Core (in Awesomium.Core.dll) Version: 1.7.6.0
Syntax

public sealed class WebSession : NativeViewModel

The WebSession type exposes the following members.

Methods

  NameDescription
Public methodAddDataSource
Adds a DataSource instance for a specified host.
Public methodClearCache
Clears the cache asynchronously.
Public methodClearCookies
Clears all cookies asynchronously.
Public methodContainsDataSource
Gets if a DataSource is registered with this WebSession for the specified assetHost.
Public methodDispose
Releases this WebSession instance.
(Overrides NativeViewModelDispose.)
Protected methodFinalize (Inherited from NativeViewModel.)
Public methodGetDataSource
Gets the DataSource instance previously registered for this assetHost.
Public methodGetZoomForURL
Gets the saved zoom setting for a certain URL host (in percent). Zoom is saved per hostname.
Protected methodOnDispose
Called when an instance of this class is being disposed.
(Overrides NativeViewModelOnDispose.)
Protected methodOnPropertyChanged
Triggers the PropertyChanged event.
(Inherited from ViewModel.)
Protected methodRaisePropertyChanged
Helper method to raise the PropertyChanged event.
(Inherited from ViewModel.)
Public methodSetCookie
Sets a cookie for a certain URL asynchronously.
Top
Fields

  NameDescription
Public fieldStatic memberReservedAssetHosts
A list of asset host names that are reserved by Awesomium.NET for internal use, and they cannot be used with AddDataSource(String, DataSource).
Top
Properties

  NameDescription
Public propertyActiveDownloads
Gets a list of active download operations controlled by this WebSession.
Public propertyCanDispose
Gets if this session is not associated with any views and maintains no download operations and is therefore eligible for release.
Public propertyDataPath
Gets the disk data path of this session, if any.
Public propertyDataSources
Gets a list of DataSource instances that have been registered with this WebSession.
Public propertyHasDownloads
Gets if this WebSession is currently controlling active download operations.
Public propertyHasViews
Gets if this WebSession is currently assigned to IWebView instances.
Public propertyIsDefault
Gets if this session is the default in-memory session used with views created with no session specified.
Public propertyIsDisposed
Gets if this instance is already disposed and eligible for garbage collection.
(Inherited from NativeViewModel.)
Public propertyIsJavascriptEnabled
Gets if JavaScript is enabled on this WebSession.
Public propertyIsOnDisk
Gets if this session is being synchronized to disk (else, it's in-memory only and all data will be lost at exit).
Public propertyPreferences
Gets the preferences for this session.
Public propertyViews
Gets the IWebView instances that share this WebSession.
Top
Events

  NameDescription
Public eventDisposed
Occurs when an instance of this class has been disposed.
(Inherited from NativeViewModel.)
Public eventPropertyChanged
Occurs when the value of a property of this class, has changed.
(Inherited from ViewModel.)
Top
Remarks

IWebView instances that share the same WebSession, share the same cookies, cache, certificates, local databases as well as the same preferences (see WebPreferences).

Note Note
Due to being responsible for maintaining authentication contexts, WebSession instances are also responsible for controlling download operations that are then maintained by the WebCore. This is why a WebSession cannot be released while a download operation initiated by a view associated with it, is in progress.

Assigning a WebSession

The following table presents the various ways of assigning a WebSession to an IWebView instance, depending on the technology:
Technology Methods
Core (WebView)
  1. Create a WebSession using CreateWebSession(WebPreferences).
  2. Assign the session to a new WebView during instantiation (see CreateWebView(Int32, Int32, WebSession, WebViewType)).
WPF (WebControl)
Windows Forms (WebControl)
  • Assign a WebSession to the Windows Forms WebControl by using a WebSessionProvider component in the Windows Forms Designer. For an example, see: Using Web-Sessions
  • Assign a WebSession to the WPF WebControl programmatically, by using the WebSession property.
    Note Note
    The session must be assigned to the control before the control goes live (see IsLive), usually in the container's constructor, right after InitializeComponent or by handling the InitializeView event.
Examples

This example demonstrates creating and using a WebSession with the windowless WebView, in a non-UI application.
using ( WebSession session = WebCore.CreateWebSession( "C:\\MyCache", new WebPreferences() { CustomCSS = "::-webkit-scrollbar { visibility: hidden; }" } ) )
{
    using ( WebView view = WebCore.CreateWebView( 1280, 960, session ) )
    {
        view.LoadURL( new Uri( "http://www.awesomium.com" ) );
        view.LoadingFrameComplete += ( s, e ) =>
        {
            if ( !e.IsMainFrame )
                return;

            BitmapSurface surface = (BitmapSurface)view.Surface;
            surface.SaveToPNG( "result.png", true );
        };

        if ( WebCore.UpdateState == WebCoreUpdateState.NotUpdating )
            WebCore.Run();
    }
}
See Also

Reference