IIS7阻止使用外部IP对asp.net应用程序的请求
我有一个 asp.net 应用程序 (IIS7),我想使用外部服务器 IP 阻止对其进行访问。我只想允许使用我的域进行访问。
例如,我的域名是domain.com,IP 161.0.0.1,我想阻止访问http://161.0。 0.1/webapp/
我更喜欢
提前使用 web.config ,谢谢,
I have a asp.net app (IIS7), and I want block access to it using external server IP. I only want to allow access using my domain.
For example, my domain is domain.com and IP 161.0.0.1 and I want to block the access to http://161.0.0.1/webapp/
I prefer do it using web.config
Thx in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 IIS 中,您可以准确配置您希望站点响应的 IP/DNS 名称组合。您可以轻松地强制它只响应特定的 IP。
对于 IIS 7:
现在,您的站点将仅响应该特定域名,而不会仅通过 IP 地址响应。
如果您的站点使用 SSL 证书,请参阅以下问题,其中讨论如何配置 IIS 以强制使用主机名:
https://serverfault.com/ questions/96810/iis7-cant-set-host-name-on-site-with-ssl-cert-and-port-443
链接到:
http://www.sslshopper.com/article- ssl-host-headers-in-iis-7.html
此链接更适合完全通过 UI 完成此操作:http://blog.armgasys.com/?p=80
In IIS you configure exactly what IP / DNS name combination you want the site to respond to. You can easily force it to only respond on a particular IP.
For IIS 7:
Now your site wil only respond to that particular domain name and won't respond via IP address only.
If your site uses an SSL certificate then see the following question which talks about how to configure IIS to force the hostname to be used:
https://serverfault.com/questions/96810/iis7-cant-set-host-name-on-site-with-ssl-cert-and-port-443
which links to:
http://www.sslshopper.com/article-ssl-host-headers-in-iis-7.html
This link is even better for doing it entirely through the UI: http://blog.armgasys.com/?p=80
好的,如果您希望通过 DNS 名称而不是 IP 访问站点,唯一区分的方法是检查标头中请求的主机名。据我所知,有两种方法可以实现:
1) 在 IIS 管理器中配置绑定对话框。这是最容易设置的,但不适用于 HTTPS。只需将 www.domain.com 放入主机名字段,对该 IP 的请求就会被拒绝。对于 HTTPS,如果您的安全证书适用于特定主机名,则用户在尝试通过 IP 连接时将收到安全警告,但通常他们可以覆盖该警告(取决于浏览器设置)。
编辑:Chris Lively 提供了一种使此方法也适用于 HTTPS 绑定的方法,请参阅他的答案以获取更多信息。
2) 或者,您可以检查代码中的标头。下面是一个
IHttpModule
的示例,它可以完成您想要的任务。它也是在 web.config 中配置的嵌入式解决方案。代码:
Web.config:
OK so if you want the Site to be accessible via DNS name but not via IP, the only way to distinguish that is to examine the requested host name in the header. There are two ways to do that I know of:
1) Configure Bindings dialog in IIS Manager. This is the easiest to set up but doesn't work for HTTPS. Just put www.domain.com into the hostname field and requests to the IP will be rejected. For HTTPS if your security certificate is for a specific hostname, the user will get a security warning if they try to connect via IP, but typically they can override the warning (depending on browser settings).
Edit: Chris Lively has linked to a way to make this method work for HTTPS bindings as well, see his answer for more information.
2) Alternately you can examine the header in code. Here is an example of an
IHttpModule
which accomplishes what you want. It is also a drop-in solution that is configured in web.config.Code:
Web.config: