我可以从网页API访问的IIdentity

我可以从网页API访问的IIdentity

本文介绍了我可以从网页API访问的IIdentity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对现有的MVC应用程序增加了一些网页API服务。我有我的MVC控制器来获得存储在CustomIdentity用户对象的模型粘合剂。我试图重现此为我的Web API操作。

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.

在MVC控制器或它的粘合剂,我可以使用

In the MVC Controller or its binders I can use

controllerContext.HttpContext.User.Identity

的ApiController不具有HttpContext对象。反正从Web API访问的IIdentity对象?

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财产用户已经取代了这一点: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

这篇关于我可以从网页API访问的IIdentity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 14:18