[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: 1.7.0.3 (1.7.0.3)

Syntax

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

Parameters

dataPath
Type: System..::..String
The directory path to store the data.
prefs
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.

Remarks

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).

Note
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.

Examples

CopyC#
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 );
            WebCore.Update();
        }

        BitmapSurface surface = (BitmapSurface)view.Surface;
        surface.SaveToPNG( "result.png", true );
    }
}
CopyVB.NET
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
            Thread.Sleep(100)
            WebCore.Update()
        Loop

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

Exceptions

ExceptionCondition
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