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. Um dies zu erreichen, wähle ich WebDAV.
Das Problem besteht darin, 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);
}
}
}
Bearbeiten (06.01.2025):
Mein aktuelles Problem ist, dass ich das Projekt ausführen kann, es mir aber nicht möglich ist, PROFIND anzurufen:

Code: Select all

curl -X PROPFIND http://localhost:5242/api/webdav/yourfile.txt -i
HTTP/1.1 404 Not Found
Content-Length: 0
Date: Mon, 06 Jan 2025 08:22:47 GMT
Server: Kestrel
Andere Aufrufe der API funktionieren einwandfrei:

Code: Select all

curl -X GET http://localhost:5242/WeatherForecast/GetWeatherForecast
[{"date":"2025-01-07","temperatureC":-5,"summary":"Freezing","temperatureF":24},{"date":"2025-01-08","temperatureC":35,"summary":"Chilly","temperatureF":94},{"date":"2025-01-09","temperatureC":49,"summary":"Bracing","temperatureF":120},{"date":"2025-01-10","temperatureC":41,"summary":"Bracing","temperatureF":105},{"date":"2025-01-11","temperatureC":50,"summary":"Balmy","temperatureF":121}]
Hier das Protokoll (ich habe den Inhaltsstammpfad für diesen Beitrag manuell durch *** ersetzt)

Code: Select all

info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5242
info: Microsoft.Hosting.Lifetime[0]
Application started.  Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: ***
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: The "PROPFIND" HTTP method is not supported.
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperations(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwaggerDocumentWithoutFilters(String documentName, String host, String basePath)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwaggerAsync(String documentName, String host, String basePath)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post