开发者

Keep an object for the time the connection is running in ASP.NET

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 Ht开发者_StackOverflow社区tp 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜