.NET 远程处理有类似 OnClientConnected 事件之类的东西吗?
我在我的服务器上使用类似的东西:
TcpServerChannel channel = new TcpServerChannel(settings.RemotingPort);
ChannelServices.RegisterChannel(channel, true);
RemotingServices.Marshal(myRemoteObject, "myRemoteObject");
我想订阅某种事件,以便每当远程客户端连接到 myRemoteObject 时,我都可以检查 Thread.CurrentPrincipal.Identity.Name 来决定是否授权他。
目前我正在 myRemoteObject 的每个公开的远程方法中进行授权检查,这是一个混乱的......
I'm using something like this on my server:
TcpServerChannel channel = new TcpServerChannel(settings.RemotingPort);
ChannelServices.RegisterChannel(channel, true);
RemotingServices.Marshal(myRemoteObject, "myRemoteObject");
I would like to subscribe to some kind of event so that whenever a remote client connects to myRemoteObject, I can check the Thread.CurrentPrincipal.Identity.Name to decide whether to authorize him.
Currently I'm doing the authorizing check in every exposed remote method of myRemoteObject which is a messy...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我的远程处理应用程序中,我定义了一个特殊的对象/接口,客户端首先需要授权。如果客户端成功授权远程对象,则特殊对象返回。所以你在一处获得授权。
它看起来像这样。
在您的应用程序中,您托管 Portal-Object
In my remoting application i defined a special object/interface where clients first need to authorize. The special object then returns, if the client successfully authorized the remote object. So you have the authorization at one place.
It looks something like this.
In your application you host the Portal-Object
您可以使用类似 PostSharp 的内容来从每个方法中提取检查 - 只需在 AOP 建议中执行即可。 (您将其应用于公开其方法的类,而不是客户端连接。)
这种方法独立于您用于远程处理的任何传输 - 它只是排除了远程中所有方法的授权横切关注点班级。
You could use something like PostSharp to factor out the check from every method - just do it in the AOP advice. (You apply this to the class which is exposing its methods, not to the client connection.)
This approach is independent of whatever transport you use for remoting - it just factors out the cross-cutting concern of authorization across all the methods in your remoted class.