类似于request.ASP.NET 5中的属性 [英] What is an analog of request.Properties in ASP.NET 5
问题描述
在WebApi2中,通常将任意对象放入HttRequestMessage.Properties
.通常,它使用诸如request.SetUserRights()
这样的扩展方法,其中SetUserRights
只是将一个对象放入request.Properties[HttpPropertyKey.UserRights]
.
In WebApi2 it was common to put arbitrary objects into HttRequestMessage.Properties
. Usually it was doing with extension-methods like request.SetUserRights()
where SetUserRights
just put an object into request.Properties[HttpPropertyKey.UserRights]
.
现在,在ASP.NET 5中,HttpRequest
中没有此类属性.
Now in ASP.NET 5 there is no such property in HttpRequest
.
应该使用哪种模式与http请求一起传递任意对象?
What pattern is supposed to be be used for passing arbitrary objects along with http request?
在WebApi中用于将对象放入请求中.通常使用属性过滤器. AspNet5中仍然有过滤器,因此可以将问题改写为:过滤器应在何处放置特定于请求的公共数据. 这样的数据的示例可以是:当前用户的角色,当前用户的语言等等.
In WebApi for putting objects in request.Properties filters were used usually. We still have filters in AspNet5, so the question can be rephrased as: where should a filter put common data specific for the request. Examples of such data can be: current user's roles, current user's language and so on.
推荐答案
HttpContext
类具有 Items
属性,您可以将其用于此目的.
HttpContext
class has Items
property which you can use for this purpose.
这篇关于类似于request.ASP.NET 5中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!