抑制某些集线器或方法的代理生成 [英] Suppress proxy generation for some hubs or methods

查看:70
本文介绍了抑制某些集线器或方法的代理生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用SignalR,我有一个情况,我将有一个SignalR站点,它将向客户端广播消息,但我还需要一个实际触发这些消息的管理界面。管理页面将调用服务器端方法,这些方法将为常规用户调用客户端Javascript方法。所以我想我可以设置两个独立的集线器(一个用于管理员,一个用于其他人)或者我可以在单个集线器中使用方法,只能由管理员调用以检查授权。



但除了授权之外,我还希望SignalR不包含管理方法或生成的Javascript代理类中的管理中心,这样我就不会做广告他们的存在(再次 - 这不是唯一的安全,我将检查授权)。我是否可以在各个集线器或集线器中的方法上设置属性或属性,以阻止它们包含在代理中(但仍然可以从Javascript调用它们)?我知道您可以在 HubConfiguration 中将 EnableJavaScriptProxies 设置为 false ,但这似乎是全球性的,我想保留我希望常规客户端使用的东西的代理。

解决方案

我们今天无法从代理中排除特定方法。您必须重新实现自己的代理生成器,它基本上执行我们在默认impl中所做的操作,但具有某些属性的知识,可以跳过特定方法的生成。



我们可以想象在SignalR的未来版本中添加它。如果您对此感到强烈,请在github上提出问题。



这是默认实现(如果我们将更多方法设置为虚拟和非静态,那将会更容易)。 / p>

https://github.com/SignalR/SignalR/blob/master/src/Microsoft.AspNet.SignalR.Core/Hubs/DefaultJavaScriptProxyGenerator.cs


I'm starting out with SignalR and I have a situation where I'm going to have a SignalR site that will be broadcasting messages to clients, but I also need an admin interface that will actually trigger those messages. The admin page will call server side methods that will, in turn, call client side Javascript methods for regular users. So I'm thinking I can either set up two separate hubs (one for admin, one for everybody else) or I can have methods in a single hub that can only be called by the admin that will check authorization.

But in addition to the authorization, I'd like to have SignalR not include admin methods or an admin hub in the generated Javascript proxy classes so that I'm not advertising their existence (again - this is NOT the only security, I will be checking authorization). Is there an attribute or property I can set on individual hubs or on methods within a hub that will suppress them from being included in the proxy (but still have them callable from Javascript)? I know you can set EnableJavaScriptProxies to false in your HubConfiguration, but that seems to be global and I'd like to keep the proxy for the stuff I do want the regular client to be using.

解决方案

We don't have a way of excluding specific methods from the proxy today. You'd have to re-implement your own proxy generator that basically does what we do in our default impl but has knowledge of some attribute to skip generation of specific methods.

We can conceivable add this in a future version of SignalR. File an issue on github if you feel strongly about having this.

Here's the default implementation (it would have been easier if we made more methods virtual and non static).

https://github.com/SignalR/SignalR/blob/master/src/Microsoft.AspNet.SignalR.Core/Hubs/DefaultJavaScriptProxyGenerator.cs

这篇关于抑制某些集线器或方法的代理生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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