Click or drag to resize

DavContextBase Constructor (HttpContext)

IT Hit WebDAV Classes Reference
Initializes context for IIS/ASP.NET based server.

Namespace: ITHit.WebDAV.Server
Assembly: ITHit.WebDAV.Server (in ITHit.WebDAV.Server.dll) Version: 4.5.3121.0
Syntax
public DavContextBase(
	HttpContext context
)

Parameters

context
Type: System.WebHttpContext
An ASP.NET HttpContext object.
Remarks

You must create a new context in each request to your WebDAV server passing ASP.NET context.

This method instance is optimized for processing requests in IIS/ASP.NET-based server.

Examples

The code below is part of 'WebDAVServer.NtfsStorage' sample provided with the SDK.

public class DavHandler : IHttpHandler
{
    private readonly string license = File.ReadAllText(HttpContext.Current.Request.PhysicalApplicationPath + "License.lic");

    private static readonly bool debugLoggingEnabled =
        "true".Equals(
            ConfigurationManager.AppSettings["DebugLoggingEnabled"],
            StringComparison.InvariantCultureIgnoreCase);

    public bool IsReusable
    {
        get { return true; }
    }


    public void ProcessRequest(HttpContext context)
    {
        DavEngine engine = getOrInitializeEngine(context);

        context.Response.BufferOutput = false;
        DavContext ntfsDavContext = new DavContext(context);
        engine.Run(ntfsDavContext);
    }

    private DavEngine initializeEngine(HttpContext context)
    {

        ILogger logger = Logger.Instance;
        var engine = new DavEngine
        {
            Logger = logger

            // Use idented responses if debug logging is enabled.
            , OutputXmlFormatting = debugLoggingEnabled ? Formatting.Indented : Formatting.None
        };

        engine.License = license;

        return engine;
    }

    private DavEngine getOrInitializeEngine(HttpContext context)
    {
        //we don't use any double check lock pattern here because nothing wrong
        //is going to happen if we created occasionally several engines.
        const string ENGINE_KEY = "$DavEngine$";
        if (context.Application[ENGINE_KEY] == null)
        {
            context.Application[ENGINE_KEY] = initializeEngine(context);
        }

        return (DavEngine)context.Application[ENGINE_KEY];
    }
}
See Also