试图找出一种优雅的方式来坚持在ASP.NET MVC请求管道对象之间的数据 [英] Trying to figure out an elegant way to persist data between objects in ASP.NET MVC Request Pipeline

查看:87
本文介绍了试图找出一种优雅的方式来坚持在ASP.NET MVC请求管道对象之间的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

框架:ASP.Net MVC 3

Framework: ASP.Net MVC 3

当一个请求到来时,我拦截通过全局过滤器的请求,并执行数据库查询的基础上的子域。需要从DB查找返回int值被保存到其他对象(即控制器),以使数据块命中不需要每当可能需要该数据被再次进行。

When a request comes in, I am intercepting the request through a global filter and performing a database look up based on the subdomain. The return int from the DB lookup needs to be persisted to other objects (i.e. Controllers) so that the DB hit doesn't need to be performed again whenever that data might be needed.

我希望避免使用cookie因为这个信息系统的相关部分,我不想依靠被启用Cookie。

I was hoping to avoid using cookies since this information is a pertinent part of the system and I didn't want to rely on cookies being enabled.

我看了相关的问题<一href=\"http://stackoverflow.com/questions/2471815/standard-way-to-persist-data-between-requests-in-asp-net-mvc\">here和<一个href=\"http://stackoverflow.com/questions/678872/how-to-persist-a-data-set-between-mvc-calls\">here它没有提供任何好的答案。

I have read the related questions here and here which have not provided any good answers.

其实,我有两个问题:


  1. 截至目前,我想出了一个子域管理器对象由它来完成繁重的任务,并通过我的IoC有管理的对象是HTTP请求作用域,我可以要求作为一个可能的解决方案过程中随时获取该经理。

  1. As of now I had come up with a Subdomain manager object which does the heavy lifting and through my IoC have the manager object be HTTP Request scoped and I can grab that manager anytime during the request as a possible solution.

有没有更好的方式来进行不同的对象这一信息在MVC请求管道我已经看过它后? - 我曾研究把信息反馈到莫名其妙的要求(这涉及到问题#2)

Is there a better way to carry this information across different object in the MVC request pipeline after I have looked it up? - I had examined the idea of putting the information back into the request somehow (which pertains to question #2).

如果你使用Request存储的数据(即拦截的要求,进行查找,写入请求),其中将持有该信息的逻辑位置?

If you were to use the Request to store the data (i.e. intercept the request, perform look up, write to the request) where would be the logical place to hold that information?

我回顾了会议,但,这似乎是紧密联系在一起的Web服务器被配置为会议的方式,我已经讲过了,我不想使用Cookie。如后期数据和查询字符串集合其他领域锁定为他们的安全考虑。

I reviewed the session but this seems to be closely tied to the way the web server is configured for sessions and I already mentioned I don't want to use cookies. Other areas such as post data and query string collections are locked down for their security reasons.

有什么建议?

推荐答案

1是pretty接近。

1 Is pretty close.

您的子经理也许可以是个单(使用IOC容器也许),为查找一个子域名一旦数据已初步加载一个简单的静态字典。如果你担心有这个初始加载发生,无多次你可以看看取决于制作数据库调用的开销分布式缓存(AppFabric中,NCACHE,内存缓存)执行数据负载在多个服务器上syncd。

Your SubDomain manager could probably be a singleton (using your IOC container perhaps), with a simple static Dictionary for looking up a subdomain once the data has been initially loaded. If you are concerned about having this initial load occur and be syncd across several servers without executing the data load multiple times you could look at a distributed cache (appfabric, ncache, memcache) depending on the overhead of making the DB call.

我不会用HttpContext.Item但是存储的ID。我会用你的IOC容器注入到你的控制器(S)(物业注入可能)这一点。使用最IOC容器,你应该能够有一个Htt的prequest开始这场火灾和最后一个持续的用户会话/交易的生命周期。

I would not use HttpContext.Item to store the Id however. I would use your IOC container to Inject this into your controller(s) (Property inject probably). Using most IOC containers you should be able to have this fire on the start of a HttpRequest and last last the lifetime of the "User Session/Transaction".

NHibernate的挖洞让所有这一切如此容易地实现它的可笑 http://nhforge.org /wikis/burrow/default.aspx

NHibernate Burrows allows all of this to be implemented so easily it's laughable http://nhforge.org/wikis/burrow/default.aspx

这篇关于试图找出一种优雅的方式来坚持在ASP.NET MVC请求管道对象之间的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆