技術(shù)頻道導(dǎo)航
HTML/CSS
.NET技術(shù)
IIS技術(shù)
PHP技術(shù)
Js/JQuery
Photoshop
Fireworks
服務(wù)器技術(shù)
操作系統(tǒng)
網(wǎng)站運(yùn)營(yíng)

贊助商

分類目錄

贊助商

最新文章

搜索

[解決]ASP.NET Web.config ipSecurity 500內(nèi)部服務(wù)器錯(cuò)誤

作者:admin    時(shí)間:2022-9-1 17:3:41    瀏覽:

今天看到一篇文章,說是 ASP.NET 站點(diǎn)可以在 Web.config 配置 ipSecurity 來拒絕某IP(段)訪問網(wǎng)站,于是躍躍欲試,自己也折騰一下。

此前我已經(jīng)成功在IIS里設(shè)置拒絕某IP(段)訪問網(wǎng)站了,參考文章:

然而事情并不順利,我添加代碼后,返回了一個(gè)錯(cuò)誤提示:500 - 內(nèi)部服務(wù)器錯(cuò)誤。我使用的代碼是(示例):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <security>
      <ipSecurity>
        <clear/>
        <add ipAddress="192.168.100.1"/>
      </ipSecurity>
    </security>
  </system.webServer>
</configuration>

經(jīng)查詢了解到需要修改一下配置文件,操作如下。

打開 applicationHost.config 文件(位于):

  • %windir%\system32\inetsrv\config\applicationHost.config

找到 <sectionGroup name="system.webServer"> 這個(gè)節(jié)點(diǎn),然后把此節(jié)點(diǎn)內(nèi)的下面這行:

  1. <section name="ipSecurity" overrideModeDefault="Deny" />

改為:

  1. <section name="ipSecurity" overrideModeDefault="Allow" />

applicationHost.config
點(diǎn)擊圖片放大

保存文件。

這樣,代碼就能運(yùn)行正常了。

設(shè)置后,被拒絕IP訪問網(wǎng)站時(shí)就返回 403 - 禁止訪問:訪問被拒絕 的提示。

 403 - 禁止訪問:訪問被拒絕

配置示例

以下配置示例為默認(rèn)網(wǎng)站添加了兩個(gè) IP 限制;第一個(gè)限制拒絕訪問 IP 地址 192.168.100.1,第二個(gè)限制拒絕訪問整個(gè) 169.254.0.0 網(wǎng)絡(luò)。

<system.webServer>
  <security>
    <ipSecurity>
      <add ipAddress="192.168.100.1" />
      <add ipAddress="169.254.0.0" subnetMask="255.255.0.0" />
    </ipSecurity>
  </security>
</system.webServer>

相關(guān)文章

標(biāo)簽: Web_config  ipSecurity  
x
  • 站長(zhǎng)推薦
/* 左側(cè)顯示文章內(nèi)容目錄 */