c# - Inject current user to OWIN Self-Host Web API 's service -
i using services business logic in owin self-host web api, , want inject current user services.
this identityservice currentuser property:
public class identityservice : iidentityservice { private readonly usermanager<user, int> usermanager; public identityservice(usermanager<user, int> usermanager) { if (usermanager == null) { throw new argumentnullexception("usermanager"); } this.usermanager = usermanager; } public user currentuser { { var identity = thread.currentprincipal; if (identity == null || identity.identity == null || !identity.identity.isauthenticated) { if (httpcontext.current == null || httpcontext.current.user == null) { return null; } identity = httpcontext.current.user; } var user = this.usermanager.findbyname(identity.identity.name); return user; } } }
for self-hosted web api httpcontext.current null, should check it? perhaps better way determine current user?
Comments
Post a Comment