[This is preliminary documentation and is subject to change.]

Creates a WebSession which will be used to store all user-data (such as cookies, cache, certificates, local databases, etc).

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


public static WebSession CreateWebSession(
	string dataPath,
	WebPreferences prefs
Visual Basic
Public Shared Function CreateWebSession ( _
	dataPath As String, _
	prefs As WebPreferences _
) As WebSession
Visual C++
static WebSession^ CreateWebSession(
	String^ dataPath, 
	WebPreferences prefs


Type: System..::..String
The directory path to store the data.
Type: Awesomium.Core..::..WebPreferences
A WebPreferences instance specifying session specific preferences.

Return Value

Returns a new WebSession instance that you can use with any number of IWebView instances.


The returned WebSession instance can be used when you create a IWebView, by either specifying it as the session parameter in CreateWebView(Int32, Int32, WebSession), or by assigning it to the WebSession property of technology specific WebControls, when you instantiate them.

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

You are responsible for disposing this WebSession when you are done using it however note that you cannot dispose a WebSession instance that is assigned to active views.


using ( WebSession session = WebCore.CreateWebSession( "C:\\MyCache", new WebPreferences() { CustomCSS = "::-webkit-scrollbar { visibility: hidden; }" } ) )
    using ( WebView view = WebCore.CreateWebView( 1280, 960, session ) )
        bool finishedLoading = false;

        view.LoadURL( new Uri( "http://www.awesomium.com" ) );
        view.LoadingFrameComplete += ( s, e ) =>
            if ( e.IsMainFrame )
                finishedLoading = true;

        while ( !finishedLoading )
            Thread.Sleep( 100 );

        BitmapSurface surface = (BitmapSurface)view.Surface;
        surface.SaveToPNG( "result.png", true );
Using session As WebSession = WebCore.CreateWebSession("C:\MyCache", New WebPreferences() With {.CustomCSS = "::-webkit-scrollbar { visibility: hidden; }"})
    Using view As WebView = WebCore.CreateWebView(1280, 960, session)
        Dim finishedLoading As Boolean = False

        view.LoadURL(New Uri("http://www.awesomium.com"))
        AddHandler view.LoadingFrameComplete, Sub(s, e)
                                                    If e.IsMainFrame Then
                                                        finishedLoading = True
                                                    End If
                                              End Sub    

        Do While Not finishedLoading

        Dim surface As BitmapSurface = CType(view.Surface, BitmapSurface)
        surface.SaveToPNG("result.png", True)
    End Using
End Using


System.IO..::..IOException The directory specified by dataPath is read-only.
System..::..UnauthorizedAccessException The caller does not have the required permission.
System..::..ArgumentExceptiondataPath is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars -or- dataPath is prefixed with, or contains only a colon character (:).
System..::..ArgumentExceptiondataPath is null.
System.IO..::..PathTooLongException The specified dataPath exceeds the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters and file names must be less than 260 characters.
System.IO..::..DirectoryNotFoundException The specified dataPath is invalid (for example, it is on an unmapped drive).
System..::..NotSupportedExceptiondataPath contains a colon character (:) that is not part of a drive label ("C:\").

See Also