0

I am building a RESTful API with the .net MVC Web API framework, and want to store some user information that comes in for updates/saves.

I am using an authorization attribute that authorizes based on tokens. When a valid token is seen, I want to grab that user's information from the database, and store the user object to be used inside the controller.

Is there an easy way to do this? It looks like in the regular .net MVC you would just store the user in the HttpContext. That seems to no longer exist though.

4

2 回答 2

0

您可以通过在操作参数中使用用户对象并注册一个知道如何处理的自定义绑定器来对用户对象进行自定义参数绑定。

请参阅此处如何使用 Web API 进行参数绑定:http: //blogs.msdn.com/b/jmstall/archive/2012/04/16/how-webapi-does-parameter-binding.aspx

于 2012-06-18T06:29:38.680 回答
0

在 RC 中,可以通过 ApiController 的 User 属性获取当前用户的信息:

http://msdn.microsoft.com/en-us/library/system.web.http.apicontroller.user(v=vs.108)

于 2012-06-18T10:41:23.103 回答