cookies - Asp.net core 2.0 services.AddCookieAuthentication event OnValidatePrincipal -
recently stumble upon problem seems hard solve. trying mangage new mvc6 core in windows environment. 2.0 preview2 release. problem want subscribe onvalidateprincipal in
services.addcookieauthentication( o => { ... o.events = new cookieauthenticationevents { onvalidateprincipal = principalvalidator.validateasync };
}); created class suggested in doc here in same file without namespace like:
public static class principalvalidator { public override async task validateasync(cookievalidateprincipalcontext context) { string usersessiontoken = context.principal.claims.firstordefault(x => x.type == claimtypes.name)?.value; if (usersessiontoken == null) { context.rejectprincipal(); await context.httpcontext.authentication.signoutasync(cookieauthenticationdefaults.authenticationscheme); } } }
so .. problem when try compile receive 2 errors :
relative line onvalidateprincipal = principalvalidator.validateasync error "an object reference required non-static field, method, or property 'principalvalidator.validateasync(cookievalidateprincipalcontext)"
relative line public override async task validateasync(cookievalidateprincipalcontext context) error "validator.validateasync(cookievalidateprincipalcontext)': no suitable method found override"
i add references using microsoft.aspnetcore.http; , using microsoft.aspnetcore.authentication.cookies;
what's wrong in code ?? ; missing reference ?? or correct way override validateasync method in current release ??
hope , thanks
wiki
Comments
Post a Comment