【问题标题】:Use web.config ipsecurity to restrict access to a single method使用 web.config ipsecurity 限制对单个方法的访问
【发布时间】:2015-07-30 15:16:30
【问题描述】:

我无法找到有关此的任何信息。

在 web.config 中,是否可以限制对 .svc/controller 中单个方法/端点的访问?还是必须限制对整个控制器的访问?

例如这可行,但限制了对整个 SVC 的访问:

<location path="ManagementService.svc">
    <system.webServer>
        <security>
            <ipSecurity configSource="config\ipFilter.config" />
        </security>
    </system.webServer>
</location>

如果我的 SVC 中有两种方法,并且我不想过滤其中一种方法,我是否可以改写如下内容:

<location path="ManagementService.svc/DeleteUser">
    <system.webServer>
        <security>
            <ipSecurity configSource="config\ipFilter.config" />
        </security>
    </system.webServer>
</location>

限制对单个方法的访问,同时让其他方法可以访问?

如果答案是否定的,那是不可能的,实现这一目标的最佳选择是什么?只是在代码中检查 IP?

【问题讨论】:

标签: c# asp.net wcf web-config


【解决方案1】:

是的,这是可能的,但要按端点过滤,您必须在行为级别使用 IFFilter 而不是 system.webServer,这会影响所有端点。

从 system.WebServer 中移除安全标签并添加 at 行为,如下所示:

   <serviceBehaviors>
    <behavior name="Filter1"> 
      <IPFilter filter="192.168.*.* 127.0.0.1" />           
    </behavior>
   </serviceBehaviors>

当然,您需要为要配置的每个端点创建不同的行为。

按方法也可以,但需要代码实现。

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2012-02-15
    • 1970-01-01
    • 2011-07-25
    • 2011-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    相关资源
    最近更新 更多