Closed
Description
Hello,
I found problem when I converted app from .NET Core 2.2 into 3.0.
In 3.0 is context.Resource
not anymore of type AuthorizationFilterContext, but instead Microsoft.AspNetCore.Routing.RouteEndpoint. Is there anything I'm missing (some changes in configuration or some other place)?
If did really changed, is there any way to redirect from handlers?
Any help is greatly appreciated.
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context,
T requirement)
{
var resource = context.Resource; // 2.2 - AuthorizationFilterContext
// 3.0 - RouteEndpoint
if (context.Resource is AuthorizationFilterContext mvcContext) // in 3.0 results in null
{
}
}
Thank you
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: b1141d92-adeb-6841-229f-914c808f9a2b
- Version Independent ID: 7089b376-949f-c1c6-c37a-5d8cc7ecf104
- Content: Policy-based authorization in ASP.NET Core
- Content Source: aspnetcore/security/authorization/policies.md
- Product: aspnet-core
- Technology: aspnetcore-security
- GitHub Login: @Rick-Anderson
- Microsoft Alias: riande
Activity
FeodorFitsner commentedon Jun 11, 2019
This is the solution: dotnet/aspnetcore#11075
PudottaPommin commentedon Jul 19, 2019
Not exactly, because I need to set RedirectToActionResult to redirect from this handler into specified action. Like
sbwalker commentedon Aug 27, 2019
context.Resource used to provide access to HttpContext so that you could enforce restrictions based on various aspects of the Request, etc... for example: https://www.khalidabuhakmeh.com/asp-net-core-resource-authorization-with-authorizationhandler. How can this be done in ASP.NET Core 3?
PudottaPommin commentedon Sep 14, 2019
@sbwalker your link is broken
Rick-Anderson commentedon Sep 14, 2019
@HaoK should this go in the 2.2 to 3.0 migration guide?
sbwalker commentedon Sep 14, 2019
Sorry.. the link was working when I posted it. I found the answer to my question - you now need to access HttpContext through HttpContextAccessor:
HaoK commentedon Sep 24, 2019
This is a sideeffect of the endpoint routing changes, so maybe it should go with whatever docs are related to that change?
[-].NET Core 3.0 accessing MVC request context[/-][+]access HttpContext through HttpContextAccessor in ASP.NET Core 3.0[/+]26 remaining items