在 ASP.NET 中运行连接时保留一个对象

发布于 2024-08-30 05:23:55 字数 396 浏览 2 评论 0原文

我正在使用 ASP.NET 开发一项 Web 服务,不是 .asmx 或 WCF,它是自定义的,所以我正在使用 Http 类(上下文、请求、响应等)。会话已禁用。我正在使用自己的处理程序和模块。

我想在连接处于活动状态时保持对象处于活动状态并可访问。我的意思是,输入一个请求,我为其分配一个 DbCommand,只要该连接正在执行操作,该连接就会使用该命令,当该连接结束时,应该释放该对象。

我想,我可以将其添加到我的 IPrincipal 实现中,然后当在模块中对连接进行身份验证并检索用户时,我可以将该 DbCommand 添加到 IPrincipal 中,这样我就可以从代码中的任何位置检索它,在模块 EndRequest 事件之后,我可以处理它,但我不知道是否有更好的方法来做到这一点。

你怎么认为?

干杯

I'm developing a web service with ASP.NET, is not an .asmx or WCF, it's a custom one, so I'm working with the Http classes (context, request, response, etc..). Session is disabled. I'm working with my own handler and module.

I'd like to keep a object alive and accessible for the time the connection is alive. I mean, a request enters, I assign a DbCommand to it and that connection will use that command as long is doing things, when that connection is ended, the object should be disposed.

I've thought, that I can add it to my IPrincipal implementation, then when the connection is authenticated in the module and the user retrieved, I can add that DbCommand to the IPrincipal, so I can retrieve it from wherever I want in the code, and after in the module EndRequest event, I can dispose it, but I don't know if there is a better approach to do this.

What do you think?

cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱的十字路口 2024-09-06 05:23:56

它在一定程度上取决于您的 WCF 配置。

我建议您阅读本文,因为它可能会让您深入了解您想要采取的方向。
http://msdn.microsoft.com/en-us/magazine/cc163590。 aspx

您的客户端将如何连接到该服务?

您还可以在服务上使用单例模式(因此它及其数据在“会话”中持续存在),并基于每个用户将数据存储在服务对象本身中。

It is somewhat dependent on your WCF configuration.

I suggest you read this, as it may give you some insight into the direction you want to take.
http://msdn.microsoft.com/en-us/magazine/cc163590.aspx

How will your client be connecting to the service?

You can also use a singleton pattern on the service (so it and its data persists across 'sessions') and store the data in the service object itself on a per user basis.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文