Asp.net site prevents a folder or file from being accessed by the browser. asp.net site

Source: Internet
Author: User

Asp.net site prevents a folder or file from being accessed by the browser. asp.net site

There is a Config folder under the root directory of a site, which contains some txt text in json format. text is a static resource. If you know the address of this text, you can enter the address in the browser to open the text, and others can see the site configuration, which is not expected, so you need to make this folder disabled by the browser.

Method 1: Change *. txt to *. config. asp.net cannot access files with. cs,. config, and other suffixes by default. Note: Add a config file to vs and write the required configuration content. This mode is recommended. Method 2: 1 using System; 2 3 namespace System.Web 4 { 5 internal class HttpForbiddenHandler : IHttpHandler 6 { 7 public bool IsReusable 8 { 9 get10 {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.Path25 }));26 }27 }28 }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.