Asp. NET to prevent Access databases from downloading

Source: Internet
Author: User
Tags ole sql server express connectionstrings

How to prevent Access database download is a very old topic, online discussion is also more. Here we give several ways to prevent Access databases from being downloaded under ASP.

Here we assume that the Access database name is Test.mdb.

1. Put the database outside the Web directory

If your site directory is D:\www, you can put the database in D:\data this folder, and then modify the site program in the database connection string address section is: "D:\data\test.mdb", so that the database can be called normally, but cannot download, because it is not in the site directory.

Assume that you configure the database connection string in Web. config. For example:

    <connectionStrings>        <add name= "Access" connectionstring= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\data\test.mdb "providername=" System.Data.OleDb "/>    </connectionStrings>
2. Put the database under the App_Data system folder

Starting with the. Net2.0, there is a App_Data directory dedicated to storing data files, which can be used to Access,sql Server Express, XML and other data files. The benefit of putting the database file into the App_Data folder is to prevent it from being downloaded. The file location for the connection string database can use the DataDirectory key to represent its physical path, thus eliminating the need to use the Server.MapPath () conversion when getting the connection string.

Assume that you configure the database connection string in Web. config. For example:

<connectionStrings> <add name= "Access" connectionstring= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=| Datadirectory|test.mdb "providername=" System.Data.OleDb "/> </connectionStrings>

| Datadirectory| is the representative App_Data folder.

3. Renaming database files

Rename your Access to *.asax: Because of the processing mechanism of ASP., by default, the request is rejected directly. According to this idea, you can also rename Access to *.config,*.vb, *.cs, and so on.

4. Configure IIS to Add. mdb file type mappings

To add an extension mapping for an. mdb this method is implemented by modifying the IIS settings. It takes only 2 steps.

1. Configure IIS to map the. mdb file type to the ASP. NET ISAPI.

In Windows 2003, for example, click Start-run-enter inetmgr and open Internet Services Manager. Right-click on a Web site-click Properties to pop Up the properties dialog box for this site. Click on the "Home Directory" tab and click on the "Configure" button to display the "Application Configuration" dialog box. Click "Add" to add a map, a dialog box will be displayed for you to enter the executable file: "C:\WINDOWS \microsoft.net \framework \v2.0.50727 \aspnet_isapi.dll"; Enter the extension: ". mdb ”。 As shown

2. Configure the ASP. Net. config file to map the. mdb file type to the HttpForbiddenHandler HTTP handler.

Causes the ASP. mdb file type to be mapped to an httpforbiddenhandler HTTP handle. In order to achieve this step, the following configuration must be added to the Web. config file

   
5. Add Access anti-download fields

The principle of this method is that the extension of the database into the. aspx format, from the remote access to this file, the IIS server will use it as an ASPX program, and we previously inserted the "<%" symbol in the Access database, and the ASP. NET program must be in the "<%% > "tag to execute, so there will be a" missing script close tag "500 error, others will not be able to download the Access database. It is useless to simply add "<%" to the text or Memo field in the database, because access will process the content, and in the database he will be in the form of <%, invalid! The correct way is to save the <% in the OLE Object field. Here's how:

1. First create a table and enter the following in the SQL command window: "CREATE TABLE [Notdown] ([Notdown] OLEObject)"

Then click on "!" in the toolbar. (run), so that a "notdown" table is created in the current database with the field name "Notdown" and the field type "OLE Object". 1


(Fig. 1)

2. Change the contents of the SQL query window to the following command: "INSERT INTO [Notdown] (Notdown) VALUES (0X3C25)"

The meaning of this sentence is to insert "0X3C25" data into the "Notdown" field of the "Notdown" table ("0x3c25" is 16 binary of the character "<%"). 2


(Fig. 2)

Once executed, once again look at the "table" in the database, you will find that there is an additional "notdown" table, open after the field shows "Long Binary data" 3


(Fig. 3)

Admin10000.com here has done the anti-download data sheet Notdown, you can directly download paste into your own database to use. Notdown Data Sheet

Tip 1: Whether it is an ASP site or an ASP Web site, for direct Access database suffix directly to. asp and. aspx, with FlashGet and other download tools are not mistaken, can not play anti-download role.
Tip 2: The 5th method is usually used in the Asp+access Web site.

Asp. NET to prevent Access databases from downloading

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.