简体   繁体   中英

Calling APIController action from MVC controller action

I am trying to consume API action methods form MVC controller using httpclient object, but the problem that I face is that I am unable to access the claims of the session user because the User is always null here is the calling of api method from mvc method you can notice the session user always null

please I got stuck and I need your help to overcume

Check the way identity works in one of the tutorials: https://www.tektutorialshub.com/asp-net-core/asp-net-core-identity-tutorial/

We are invoking PasswordSignInAsyncto verify and issue an authentication cookie

You should provide a cookie with the authentication value so the call can identify the target user and initialize the current user object with the appropriate values.

You can find an example of cookie addition here: How do I set a cookie on HttpClient's HttpRequestMessage

Please provide some code and authentication implementation details for us to help you more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM