一個站點根目錄下面有一個Config文件夾,這個文件夾裏面都是一些json格式的txt文本,文本是一種靜態資源,若是知道這個文本的地址,就能夠在瀏覽器中輸入地址打開這個文本,別人就能夠看到站點的配置,這是不但願的結果,因此就須要讓這個文件夾禁止被瀏覽器訪問。json
1 using System; 2 3 namespace System.Web 4 { 5 internal class HttpForbiddenHandler : IHttpHandler 6 { 7 public bool IsReusable 8 { 9 get 10 { 11 return true; 12 } 13 } 14 15 internal HttpForbiddenHandler() 16 { 17 } 18 19 public void ProcessRequest(HttpContext context) 20 { 21 PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_NOT_FOUND); 22 throw new HttpException(403, SR.GetString("Path_forbidden", new object[] 23 { 24 context.Request.Path 25 })); 26 } 27 } 28 }