在C#中有条件地隐藏asmx Web方法 [英] Hide asmx web methods conditionally in C#

查看:347
本文介绍了在C#中有条件地隐藏asmx Web方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何有条件地隐藏Web方法?如果web.config中的标志设置为false,我不想公开Web方法.如果是真的,那么我将公开该web方法.

How can I conditionally hide the web methods? I don't want to expose the web method if a flag setup in web.config is false. If it is true, then I will expose the web method.

含义:该方法仅在标志为true时对客户端可见,否则对客户端不可用.

Meaning: The method should only be visible to the client if the flag is true otherwise it should not be available for the client.

这在C#中可能吗?

推荐答案

您不能真正做到这一点.

You can't really do this.

您的客户端看到" Web方法,因为它们在WSDL中列出. WSDL的生成是相当静态的-它基于方法上的[WebMethod]属性.确实无法从生成的WSDL中删除项目.

Your clients "see" the web methods because they are listed in the WSDL. The WSDL generation is fairly static - it is based on the [WebMethod] attributes on your methods. There is really no ability to remove items from the generated WSDL.

如果您可以切换到WCF,您会发现这非常简单.同时,您只需要使用授权-阻止某些客户端调用某些方法.

If you can switch to WCF, you will find this much, much, easier. In the meantime, you'll just have to use authorization - prevent some clients from calling some methods.

这篇关于在C#中有条件地隐藏asmx Web方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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