且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何以编程方式限制对Web服务的访问?

更新时间:2023-02-08 19:15:07

是你可以轻松地做到。

Yes you can do it easily.

[WebMethod]
public bool IsAlive()
{
     string callingAddress = HttpContext.Current.Request.UserHostAddress;
     return (callingAddress == allowedAddress);
}

唯一的缺陷是维护IP地址列表。

The only pitfalls are the maintenance of the list of IP addresses.

还值得注意的是,您可以在IIS中基于每个Web应用程序配置IP地址访问控制。我在不同的时间使用了这两种方法,它实际上只取决于您希望如何维护授权IP地址列表。

It's also worth noting that you can configure IP address access control on a per web application basis from within IIS. I have used both approaches at different times and it really just comes down to how you want to maintain the list of authorised IP addresses.