Click or drag to resize

DavContextBase Class

IT Hit WebDAV Classes Reference
Serves as the abstract base class for WebDAV context.
Inheritance Hierarchy
SystemObject
  ITHit.WebDAV.ServerDavContextBase

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

The DavContextBase type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleDavContextBase(HttpContext)
Initializes context for IIS/ASP.NET based server.
Public methodDavContextBase(HttpListenerContext, HttpListenerPrefixCollection)
Initializes context for HttpListener-based server.
Public methodDavContextBase(DavRequest, DavResponse)
Initializes a new instance of the WebDAV context.
Top
Properties
  NameDescription
Public propertyEngine
Instance of DavEngine which is currently executing the request.
Public propertyException
Exception which occurred during request execution.
Public propertyRequest
Object representing current request.
Public propertyResponse
Object representing current response.
Top
Methods
  NameDescription
Public methodBeforeResponse
This method is called right before engine starts writing response.
Public methodEnsureBeforeResponseWasCalled
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodCode exampleGetHierarchyItem
Implementation of this abstract method is used by WebDAV engine to find hierarchy item objects by path.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodLocalizeSatus
May be overriden to localize HTTP status message.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks

Context holds request, response and provides item factory method GetHierarchyItem(String).

When you inherit from the DavContext class, you must override GetHierarchyItem(String) method. In this method you will search for file, folder, version or history item in your storage by path provided and return it to WebDAV engine.

In each HTTP request you will create separate instance of your class derived from DavContext with one of its overloaded constructors and pass it to Run(DavContextBase).

The DavContextBase provides several overloaded constructors. They are optimized for use with OWIN, with IIS/ASP.NET-based server and in HttpListener-based server. You can also implement your own request and response classes to run the Engine in virtually any hosting environment.

Examples

HttpListener-based server:

class Program
{
    static void Main(string[] args)
    {
        HttpListener listener = new HttpListener();
        listener.Prefixes.Add("http://localhost:8080/");
        listener.Start();
        DavEngine engine = new DavEngine();

        while (true)
        {
            HttpListenerContext context = listener.GetContext();
            MacOsXPreprocessor.Process(context.Request); // fixes headers for Mac OS X v10.5.3 or later

            if (!userAutorized(context))
            {
                context.Response.StatusCode = 401;
                showLoginDialog(context, context.Response);
                closeResponse(context);
                continue;
            }

            context.Response.SendChunked = false;

            var davContext = new MyDavContext(context, listener.Prefixes);
            engine.Run(ntfsDavContext);

            if (context.Response.StatusCode == 401)
            {
               showLoginDialog(context, context.Response);
            }

            closeResponse(context);
        }
    }
}
Thread Safety
Instance members of this class are not thread safe. You must create a separate instance of DavContextBase class for each request.
See Also