【发布时间】:2014-12-08 21:53:13
【问题描述】:
我已将配置部分设置为
<authentication mode="Forms"/>
在 api 项目和客户端项目中。
我可以从客户端项目访问 HttpContext.Current.User.Identity.Name 但不能从 api 访问
从 API 而不是从客户端项目调用时,HttpContext.Current.User.Identity.IsAuthenticated 为 false
我从 web api 项目访问 HttpContext.Current.Session 没有问题
我错过了什么吗?
【问题讨论】:
-
看不到您的代码,所以这是在黑暗中拍摄,但也许您的 api 项目无权访问您的客户端项目的会话。我相信用户信息存储在会话中,因此可能会导致这种情况。如果是这种情况,请查看:stackoverflow.com/questions/9594229/…
-
据我了解,内置表单身份验证使用 cookie 而不是“会话”,这是正确的吗?
-
你认证了吗?
-
我从 web api 项目访问 HttpContext.Current.Session 没有问题
-
我已通过身份验证。当我注销时,我无法访问除登录页面以外的任何其他页面 - 这是正确的
标签: c# asp.net-web-api web-config forms-authentication