Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
IActionContextAccessor und ActionContextAccessor wurden mit diagnose-ID ASPDEPR006als veraltet markiert. Mit der Einführung des Endpunktroutings ist es nicht mehr erforderlich, IActionContextAccessor da Entwickler direkt auf HttpContext.GetEndpoint()Aktionsdeskriptor- und Metadateninformationen zugreifen können.
Eingeführte Version
.NET 10 Preview 7
Vorheriges Verhalten
Zuvor konnten Sie auf das aktuelle ActionContextElement IActionContextAccessor zugreifen:
public class MyService
{
private readonly IActionContextAccessor _actionContextAccessor;
public MyService(IActionContextAccessor actionContextAccessor)
{
_actionContextAccessor = actionContextAccessor;
}
public void DoSomething()
{
var actionContext = _actionContextAccessor.ActionContext;
var actionDescriptor = actionContext?.ActionDescriptor;
// Use action descriptor metadata.
}
}
Neues Verhalten
Ab .NET 10 wird eine Compilerwarnung mit Diagnose-ID ASPDEPR006verwendet IActionContextAccessor und ActionContextAccessor erzeugt:
Warnung ASPDEPR006: ActionContextAccessor ist veraltet und wird in einer zukünftigen Version entfernt. Weitere Informationen finden Sie unter https://aka.ms/aspnet/deprecate/006.
Art der einschneidenden Änderung
Diese Änderung kann sich auf die Quellkompatibilität auswirken.
Grund für Änderung
Mit der Einführung des Endpunktroutings in ASP.NET Core IActionContextAccessor ist nicht mehr erforderlich. Die Endpunktroutinginfrastruktur bietet eine übersichtlichere, direktere Möglichkeit, auf Endpunktmetadaten HttpContext.GetEndpoint()zuzugreifen, indem sie sich an ASP.NET Cores Architekturentwicklung in Richtung Endpunktrouting ausrichten.
Empfohlene Aktion
Migrieren von IActionContextAccessor zu IHttpContextAccessor und Verwenden HttpContext.GetEndpoint():
Vorher:
public class MyService
{
private readonly IActionContextAccessor _actionContextAccessor;
public MyService(IActionContextAccessor actionContextAccessor)
{
_actionContextAccessor = actionContextAccessor;
}
public void DoSomething()
{
var actionContext = _actionContextAccessor.ActionContext;
var actionDescriptor = actionContext?.ActionDescriptor;
// Use action descriptor metadata
}
}
Danach:
public class MyService
{
private readonly IHttpContextAccessor _httpContextAccessor;
public MyService(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public void DoSomething()
{
var httpContext = _httpContextAccessor.HttpContext;
var endpoint = httpContext?.GetEndpoint();
var actionDescriptor = endpoint?.Metadata.GetMetadata<ActionDescriptor>();
// Use action descriptor metadata.
}
}