简体   繁体   English

从 MVC controller 操作调用 APIController 操作

[英]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 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你可以注意到 session 用户总是 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/在以下教程之一中检查身份的工作方式: https://www.tektutorialshub.com/asp-net-core/asp-net-core-identity-tutorial/

We are invoking PasswordSignInAsyncto verify and issue an authentication cookie我们正在调用PasswordSignInAsyncto来验证并发出身份验证 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.您应该提供带有身份验证值的 cookie,以便调用可以识别目标用户并使用适当的值初始化当前用户 object。

You can find an example of cookie addition here: How do I set a cookie on HttpClient's HttpRequestMessage您可以在此处找到添加 cookie 的示例: How do I set a cookie on HttpClient's HttpRequestMessage

Please provide some code and authentication implementation details for us to help you more.请提供一些代码和身份验证实现细节,以便我们为您提供更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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