DataSourceResponseCreate Method (XContainer, HttpStatusCode, WebHeaderCollection)Awesomium.NET 1.7.6Awesomium.NET
Creates a DataSourceResponse from an HTML document with user-supplied headers.

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

public static DataSourceResponse Create(
	XContainer htmlDocument,
	HttpStatusCode statusCode,
	WebHeaderCollection headers
)

Parameters

htmlDocument
Type: System.Xml.LinqXContainer
An XContainer instance representing an HTML document. This can be created from String using the ToXDocument(String)  String extension.
statusCode
Type: System.NetHttpStatusCode
The status returned with the response.
headers
Type: System.NetWebHeaderCollection
The response headers.

Return Value

Type: DataSourceResponse
Exceptions

ExceptionCondition
ArgumentException The headers collection provided contains web request headers and therefore it cannot be used with a web response.
Remarks

Unless already defined in the provided headers, the ContentType (Content-Type) and ContentLength (Content-Length) headers will automatically be added to the response.
Note Note
The expected htmlDocument can be created from String using the ToXDocument(String) String extension.
Examples

protected override void OnRequest( DataSourceRequest request )
{
    if ( request.Url.ToString() == @"asset://my-host/" )
    {
        WebHeaderCollection headers = new WebHeaderCollection() { 
            "Refresh: 0; url=http://wiki.awesomium.net", 
            "Location: http://wiki.awesomium.net" 
        };

        this.SendResponse( request, ResourceResponse.Create( 
            "More examples, <a href=\"http://wiki.awesomium.net\">here</a>.".ToXDocument(),
            HttpStatusCode.MovedPermanently,
            headers ) );

        return;
    }

    this.SendRequestFailed( request, HttpStatusCode.NotFound );
}
See Also

Reference