'ForbidResult' below is used, which causes a url redirect. Thus, Context.Items["data"]
is lost for the redirected page, which is /MicrosoftIdentity/Account/AccessDenied?ReturnUrl=SomeSite
.
public class PermissionAttribute : TypeFilterAttribute
{
private class PermissionFilter : IAsyncActionFilter
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
context.HttpContext.Items["data"] = "some data";
var authorized = check_if_it_has_permissions();
if (authorized)
{
await next();
}
else
{
context.Result = new ForbidResult(); //this is a url redirect using /MicrosoftIdentity/Account/AccessDenied?ReturnUrl=SomeSite
}
}
}
}
partial_view_header.cshtml
<div id="header">
@{
Context.Items["data"]
}
</div>
Is it possible to keep the current url, and not change the url to '/MicrosoftIdentity/Account/AccessDenied?ReturnUrl=xxx', or a way to pass data to Acccount AccessDenied view?