static void Init() { string contentRootPath = Directory.GetParent(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath)).FullName; string logPath = Path.Combine(contentRootPath, @"App_Data\WebDav\Logs"); logger.LogFile = Path.Combine(logPath, "WebDAVlog.txt"); logger.IsDebugEnabled = debugLoggingEnabled; engine = new DavEngineAsync { Logger = logger // Use idented responses if debug logging is enabled. , OutputXmlFormatting = true }; /// This license lile is used to activate: /// - IT Hit WebDAV Server Engine for .NET /// - IT Hit iCalendar and vCard Library if used in a project string license = File.ReadAllText(Path.Combine(contentRootPath, "License.lic")); engine.License = license; // Set custom handler to process GET and HEAD requests to folders and display // info about how to connect to server. We are using the same custom handler // class (but different instances) here to process both GET and HEAD because // these requests are very similar. Some WebDAV clients may fail to connect if HEAD // request is not processed. MyCustomGetHandler handlerGet = new MyCustomGetHandler(contentRootPath); MyCustomGetHandler handlerHead = new MyCustomGetHandler(contentRootPath); handlerGet.OriginalHandler = engine.RegisterMethodHandler("GET", handlerGet); handlerHead.OriginalHandler = engine.RegisterMethodHandler("HEAD", handlerHead); }
/// <summary> /// Initializes engine. /// </summary> /// <param name="context">Instance of <see cref="HttpContext"/>.</param> /// <returns>Initialized <see cref="DavEngine"/>.</returns> private DavEngineAsync initializeWebDavEngine(HttpContext context) { ILogger logger = WebDAVServer.FileSystemStorage.AspNet.Logger.Instance; DavEngineAsync webDavEngine = new DavEngineAsync { Logger = logger // Use idented responses if debug logging is enabled. , OutputXmlFormatting = true }; webDavEngine.License = license; string contentRootPath = HttpContext.Current.Request.MapPath("/"); // Set custom handler to process GET and HEAD requests to folders and display // info about how to connect to server. We are using the same custom handler // class (but different instances) here to process both GET and HEAD because // these requests are very similar. Some WebDAV clients may fail to connect if HEAD // request is not processed. MyCustomGetHandler handlerGet = new MyCustomGetHandler(contentRootPath); MyCustomGetHandler handlerHead = new MyCustomGetHandler(contentRootPath); handlerGet.OriginalHandler = webDavEngine.RegisterMethodHandler("GET", handlerGet); handlerHead.OriginalHandler = webDavEngine.RegisterMethodHandler("HEAD", handlerHead); return(webDavEngine); }
/// <summary> /// Enables processing of HTTP Web requests. /// </summary> /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the /// intrinsic server objects (for example, Request, Response, Session, and Server) used to service /// HTTP requests. /// </param> public override async Task ProcessRequestAsync(HttpContext context) { DavEngineAsync engine = getOrInitializeEngine(context); context.Response.BufferOutput = false; DavContext ntfsDavContext = new DavContext(context); await engine.RunAsync(ntfsDavContext); }
static void Init() { string contentRootPath = Directory.GetParent(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath)).FullName; string logPath = Path.Combine(contentRootPath, @"App_Data\WebDav\Logs"); logger.LogFile = Path.Combine(logPath, "WebDAVlog.txt"); logger.IsDebugEnabled = debugLoggingEnabled; webDavEngine = new DavEngineAsync { Logger = logger // Use idented responses if debug logging is enabled. , OutputXmlFormatting = true }; /// This license lile is used to activate: /// - IT Hit WebDAV Server Engine for .NET /// - IT Hit iCalendar and vCard Library if used in a project string license = File.ReadAllText(Path.Combine(contentRootPath, "License.lic")); webDavEngine.License = license; /// This license file is used to activate G Suite Documents Editing for IT Hit WebDAV Server string gSuiteLicense = File.Exists(Path.Combine(contentRootPath, "GSuiteLicense.lic")) ? File.ReadAllText(Path.Combine(contentRootPath, "GSuiteLicense.lic")) : string.Empty; if (!string.IsNullOrEmpty(gSuiteLicense)) { gSuiteEngine = new GSuiteEngineAsync(googleServiceAccountID, googleServicePrivateKey, googleNotificationsRelativeUrl) { License = gSuiteLicense, Logger = logger }; } // Set custom handler to process GET and HEAD requests to folders and display // info about how to connect to server. We are using the same custom handler // class (but different instances) here to process both GET and HEAD because // these requests are very similar. Some WebDAV clients may fail to connect if HEAD // request is not processed. MyCustomGetHandler handlerGet = new MyCustomGetHandler(contentRootPath); MyCustomGetHandler handlerHead = new MyCustomGetHandler(contentRootPath); handlerGet.OriginalHandler = webDavEngine.RegisterMethodHandler("GET", handlerGet); handlerHead.OriginalHandler = webDavEngine.RegisterMethodHandler("HEAD", handlerHead); string attrStoragePath = (ConfigurationManager.AppSettings["AttrStoragePath"] ?? string.Empty).TrimEnd(Path.DirectorySeparatorChar); if (!string.IsNullOrEmpty(attrStoragePath)) { FileSystemInfoExtension.UseFileSystemAttribute(new FileSystemExtendedAttribute(attrStoragePath, repositoryPath)); } else if (!(new DirectoryInfo(repositoryPath).IsExtendedAttributesSupported())) { var tempPath = Path.Combine(Path.GetTempPath(), System.Reflection.Assembly.GetExecutingAssembly().GetName().Name); FileSystemInfoExtension.UseFileSystemAttribute(new FileSystemExtendedAttribute(tempPath, repositoryPath)); } }
/// <summary> /// Enables processing of HTTP Web requests. /// </summary> /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the /// intrinsic server objects (for example, Request, Response, Session, and Server) used to service /// HTTP requests. /// </param> public override async Task ProcessRequestAsync(HttpContext context) { DavEngineAsync webDavEngine = getOrInitializeWebDavEngine(context); context.Response.BufferOutput = false; DavContext ntfsDavContext = new DavContext(context); GSuiteEngineAsync gSuiteEngine = getOrInitializeGSuiteEngine(context); await webDavEngine.RunAsync(ntfsDavContext); if (gSuiteEngine != null) { await gSuiteEngine.RunAsync(ContextConverter.ConvertToGSuiteContext(ntfsDavContext)); } }
/// <summary> /// Creates instance of this class. /// </summary> /// <param name="contextOptions">Context options.</param> /// <param name="userOptions">User options.</param> /// <param name="logger">Logger instance.</param> /// <param name="logMethod">Logging method for specific platform.</param> /// <param name="eventsService">Server sent events service for user notifications.</param> /// <param name="engine">Engine instance.</param> public WebDAVHttpListener( IOptions <DavContextOptions> contextOptions, IOptions <DavUserOptions> userOptions, ILogger logger, ILogMethod logMethod, EventsService eventsService, DavEngineAsync engine ) { this.contextOptions = contextOptions.Value; this.userOptions = userOptions.Value; this.logger = logger; this.eventsService = eventsService; this.engine = engine; this.logMethod = logMethod; Features.Set <IHttpRequestFeature>(new HttpRequestFeature()); Features.Set <IHttpResponseFeature>(new HttpResponseFeature()); digestProvider = new DigestAuthenticationProvider(GetPasswordAndRoles); }
/// <summary> /// Initializes engine. /// </summary> /// <param name="context">Instance of <see cref="HttpContext"/>.</param> /// <returns>Initialized <see cref="DavEngine"/>.</returns> private DavEngineAsync initializeEngine(HttpContext context) { ILogger logger = CalDAVServer.SqlStorage.AspNet.Logger.Instance; logger.LogFlags = LogFlagsEnum.LogGetResponseBody | LogFlagsEnum.LogPutRequestBody; DavEngineAsync engine = new DavEngineAsync { Logger = logger // Use idented responses if debug logging is enabled. , OutputXmlFormatting = true // Do not emit CORS headers, typically not required in case of CalDAV/CardDAV server. , CorsAllowedFor = null // Use full URIs only in case of a regular WebDAV server. Microsoft Mini-redirector does not support URIs without domain. , UseFullUris = false }; engine.License = license; string contentRootPath = HttpContext.Current.Request.MapPath("/"); // Set custom handler to process GET and HEAD requests to folders and display // info about how to connect to server. We are using the same custom handler // class (but different instances) here to process both GET and HEAD because // these requests are very similar. Some WebDAV clients may fail to connect if HEAD // request is not processed. MyCustomGetHandler handlerGet = new MyCustomGetHandler(contentRootPath); MyCustomGetHandler handlerHead = new MyCustomGetHandler(contentRootPath); handlerGet.OriginalHandler = engine.RegisterMethodHandler("GET", handlerGet); handlerHead.OriginalHandler = engine.RegisterMethodHandler("HEAD", handlerHead); // Set your iCalendar & vCard library license before calling any members. // iCalendar & vCard library accepts: // - WebDAV Server Engine license with iCalendar & vCard modules. Verify your license file to see if these modules are specified. // - or iCalendar and vCard Library license. ITHit.Collab.LicenseValidator.SetLicense(license); return(engine); }