zoukankan      html  css  js  c++  java
  • 禁止通过网页URL访问文件夹 asp.net

    我们可以通过如下的两种办法,禁止用户通过浏览器的URL地址直接访问网站服务器的文件夹。

      一、通过类和配置文件限制

      ①NET C#代码  

      新建一个类,继承IHttpHandler
      using System;
      using System.Data;
      using System.Configuration;
      using System.Linq;
      using System.Web;
      using System.Web.Security;
      using System.Web.UI;
      using System.Web.UI.HtmlControls;
      using System.Web.UI.WebControls;
      using System.Web.UI.WebControls.WebParts;
      using System.Xml.Linq;

      /// <summary>
      ///MyHandler 的摘要说明
      /// </summary>
      public class MyHandler:IHttpHandler
      {
       public void ProcessRequest(HttpContext ctx)//方法名固定
       {
       HttpResponse Response;
       ctx.Response.Write("Sorry");
      }
      }

      ②修改配置文件

      配置Web.Config
       <httpHandlers>
       <add verb="*" path="Img/*.jpg" type=" MyHandler" />
       </httpHandlers>

      当访问Img文件夹下面的任何jpg图片文件的时候,都拒绝访问打印出"Sorry"字样

      二、修改IIS的设置

      1. 打开 IIS 管理器。
      2. 在“功能”视图中,双击“目录浏览”。
      3. 在“目录浏览”页上,在“操作”窗格中单击“禁用”。

  • 相关阅读:
    Windows下MySQL8.0.23的下载与安装简单易用
    【转】decimal double的区别
    【转】.NET垃圾回收
    vs2010 断点调试故障 反编译插件引起的
    【摘】别人对面向对象的理解
    【转】C# indexof
    【转】八大排序算法总结
    【转】JS windows.open()详解
    【转】with as
    【转】SQL Server的几种约束
  • 原文地址:https://www.cnblogs.com/uftwkb24/p/8038278.html
Copyright © 2011-2022 走看看