I'm building site with ASP.NET MVC 5, and would like to secure Glimpse with existing layer of security, MVC 5 Roles. Glimpse is version 1.8.6
I wrote my implementation of IRuntimePolicy, derived from the sample code. When I run thru my code the IsAuthenticated property of request is always false. Even when I'm logged in (in the controller this property is true). Can anybody help me what I'm doing wrong? I thought setting Glimpse:DisableAsyncSupport in the app settings would help, but didn't.
This is my implementatio of IRuntimePolicy
public RuntimePolicy Execute(IRuntimePolicyContext policyContext)
{
var userManager = new UserManager(new UserStore<MyUser>(new ApplicationDbContext()));
var httpContext = HttpContext.Current;
if (httpContext.Request.IsAuthenticated) //ALWAYS FALSE, EVEN WHEN IM LOGGED IN
{
var userId = httpContext.User.Identity.GetUserId(); //User is null
if (userManager.IsInRole(userId, "Admin"))
return RuntimePolicy.On;
}
return RuntimePolicy.Off;
}
You have to add <modules runAllManagedModulesForAllRequests="true" />
or add precondition="managedHandler" for your module. See more explanation here: enter link description here There might be a performance hit in the first option.