我可以从Web API访问IIdentity吗?(Can I access IIdentity from Web API)

系统教程 行业动态 更新时间:2024-06-14 16:58:30
我可以从Web API访问IIdentity吗?(Can I access IIdentity from Web API)

我将一些Web API服务添加到现有的MVC应用程序中。 我有一个模型绑定器为我的MVC控制器获取用户对象存储在一个CustomIdentity。 我正在为我的Web API操作重现这一点。

在MVC控制器或其粘合剂我可以使用

controllerContext.HttpContext.User.Identity

ApiController没有HttpContext对象。 有没有从Web API访问IIdentity对象?

I'm adding some Web API services to an existing MVC application. I have a model binder for my MVC controllers to get the user object stored in a CustomIdentity. I'm trying to reproduce this for my Web API actions.

In the MVC Controller or its binders I can use

controllerContext.HttpContext.User.Identity

The ApiController doesn't have the HttpContext object. Is there anyway to access the IIdentity object from the Web API?

最满意答案

他们在ASP.NET MVC 4 RC中删除了GetUserPrincipal。 但是,似乎ApiController属性User已经取代了这个: http : //msdn.microsoft.com/en-us/library/system.web.http.apicontroller.user

They removed GetUserPrincipal in ASP.NET MVC 4 RC. However it seems the ApiController property User has replaced this: http://msdn.microsoft.com/en-us/library/system.web.http.apicontroller.user

更多推荐

本文发布于:2023-04-15 03:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/54516ab6034ac73fd8d641e304b2d5af.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:API   Web   access   IIdentity

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!