如何确定传入请求是否针对控制器(或与此相关的任何其他资源)?
我试图帮助减少分发数据库会话(我正在使用 NHibernate)的时间,以便仅在传入请求针对需要会话的对象时才分发一个。
我知道有一种方法可以获取 HttpApplication 中的信息,让我确定这一点,但我不确定它是否像我希望的那样直接,或者我是否必须根据路由请求实现一些逻辑。 ..ETC。
有人可以推荐某种方式让我可以审查请求以确定这一点吗?我已经审查了 HttpApplication 类和许多属性/方法,并假设它将归结为 HttpContext.Current.Request.RequestContext 中的某个位置,但我想我会看看是否有一种简单的方法可以做到这一点。
I am attempting to help reduce when I hand out a database session (I am using NHibernate) so as to only hand one out if the incoming request is for a object that requires a session.
I know there is a way to get to information in the HttpApplication that would let me determine this, but I am not sure if it is as straight forward as I would like, or if I have to implement some logic based on the route request...etc.
Can someone recommend some way that I can review the request for determining this? I have reviewed the HttpApplication class and a number of properties/methods and assuming it is going to come down to somewhere in HttpContext.Current.Request.RequestContext, but I thought I would see if there is a easy way of doing so.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是来自 Oyvind Valland 的博客,他正在做我正在寻找的事情,并检查传入的请求请求资源以确定是否需要会话。 Julian Margarintescu 提出了一个很好的观点,但为了回答实际问题,以防因其他原因需要它。
This is from Oyvind Valland's Blog who was doing precisely what I was looking for and checking the incoming request for the resource requested to determine if a session was needed. Julian Margarintescu makes a good point, but for an answer to the actual question in case it was needed for some other reason.
您应该阅读 Ayende 撰写的关于成本的文章打开会话。空/未使用的会话非常轻,您可以为任何请求创建它们,因为它们不会打开数据库连接。
You should read this post by Ayende about the cost of opening a session. Empty/unused sessions are so light you can create them for any request, as they will not open a db connection.