asp.net - How does Identity.GetUserId() finds the user Id? -


question

how user.identity.getuserid() finds current user's id?

does find user id cookies, or query database? or other methods?

problem

for reason, user.identity.getuserid() returns null when add valid bearer token http request header , send request controller's endpoint:

// mvc controller action method  [authorize] public httpresponsemessage(userinfoviewmodel model) {     // request passes authorization filter since valid oauth token      // attached request header.      string userid = user.identity.getuserid();      // however, userid null!      // other stuff... } 

when user logged app, server, using asp.net identity, validates user using db , creates valid token returns ui. token valid expiration , has inside information needed authenticate , authorize user, including user's id. next calls client side server side must done using token in http request header, server not call db again, because asp.net identity knows how decrypt token , information of user.

the use of cookies way store token in client side. commented above, have send token on next requests after login, can store token in cookies or in session storage in browser.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -