User.Identity.IsAuthenticated
总是在我的ASP.NET Web API项目中返回false
。
在帐户ApiController
中,我有以下内容:
ClaimsIdentity identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties() {
IsPersistent = isPersistent
}, identity);
登录后,User.Identity.IsAuthenticated
在false
中始终是ApiController
但在MVC控制器中为true
。
参考方案
它无法直接在APIControiller中使用HttpContext属性。为此,您必须使用System.Net.Http.HttpRequestMessage类型的Request属性。 HttpRequestMessage具有属性字典;您会发现保存您的IPrincipal对象的键MS_UserPrincipal的值。
如何在Web API中传递可选参数 - c#您能帮我在uri之间传递可选参数吗[Route("api/values/{a}/{b?}/{c?}")] public string Get(string a = "", string b = "", string c = "") { return string.Format(&…
为什么我无法更新字典中的test__user_id密钥? - python我正在更新包含数据的字典,dict_temp = {'description': 'hello', 'id': 683, 'status': u'pending', 'test__user_id': 430} 我试图使用dict_temp …
获取简短声明类型名称 - c#我正在使用Asp.Net Core和ASP.NET Identity,当我获得Claim类型时,我得到类似"type":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", "value":"123&…
Laravel 5.4 Auth::User()与关系不起作用 - php我有Table Vendors(用于测试Auth关系)和Table Vendor_users,但是我用Auth::user()不是关系和这个数据库在供应商模型中 protected $table = 'vendor_users'; public function Vendor_test(){ return $this->belong…
在PHP中使用“ auto_prepend_file”到“ .user.ini”文件 - php我想在项目的任何页面的运行时加载文件variables.php(仅包含变量),以便可以在任何地方使用变量。我创建了一个名为.user.ini的文件(并将其放置在根文件夹中):; Automatically add files before PHP document. ; http://php.net/auto-prepend-file auto_prepen…