Ich versuche, WebDAV-Unterstützung zur ASP.NET Core-Web-API hinzuzufügenC#

Ein Treffpunkt für C#-Programmierer
Guest
 Ich versuche, WebDAV-Unterstützung zur ASP.NET Core-Web-API hinzuzufügen

Post by Guest »

Auf dem Server führe ich eine ASP.NET Core-Web-API aus. Diese API wird für eine App und eine Webschnittstelle verwendet, um notwendige Informationen bereitzustellen. Eine der Informationen sind Kontaktinformationen.
Jetzt möchte ich meine Kontaktinformationen ohne zusätzliche App mit dem Adressbuch meines Smartphones synchronisieren. Ich wähle WebDAV, um dies zu erreichen.
Das Problem ist, dass ich aufgrund des benutzerdefinierten HttpAttribute wie PROPFIND. Kennt jemand eine Lösung zum Hinzufügen von WebDAV?
Das ist mein Controller:

Code: Select all

using Microsoft.AspNetCore.Mvc;

namespace Playground.Controllers
{
[Route("api/webdav")]
[ApiController]
public class WebDAVController : ControllerBase
{
private readonly string _baseDirectory = Path.Combine(Directory.GetCurrentDirectory(), "WebDAVData");

public WebDAVController()
{
// Ensure base directory exists
if (!Directory.Exists(_baseDirectory))
{
Directory.CreateDirectory(_baseDirectory);
}
}

// PROPFIND - Retrieve properties (a simple version)
[AcceptVerbs("PROPFIND")]
public IActionResult Propfind([FromQuery] string path)
{
var fullPath = Path.Combine(_baseDirectory, path ?? "");

if (!System.IO.File.Exists(fullPath) && !Directory.Exists(fullPath))
{
return NotFound();
}

// Return file or folder properties (you can extend this to include more detailed properties)
var fileInfo = new FileInfo(fullPath);

var properties = new Dictionary
{
{ "CreationDate", fileInfo.CreationTime.ToString() },
{ "LastModified", fileInfo.LastWriteTime.ToString() },
{ "Size", fileInfo.Length.ToString() }
};

return Ok(properties);
}
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post