ASP.NET database programming handles file access permissions

  • 2020-05-05 11:08:15
  • OfStack

An MDB database is just another file on the hard drive, so, like any other file, it will encounter the same file access licensing problems. This problem means that in order to read (and write, as you will see later in this book) the database file, the application running on the page must have the appropriate license to read (and write) the file in Windows.

So far, the reason the pages in the examples have "worked" is that you are using VWD Web Server, a lightweight program that runs as the user running VWD. That is, VWD Web Server runs for you, and you have been allowed to read and write the MDB file for the page connection.

However, when you run a page under IIS, the situation is a bit more complicated. At this point, the ASP.NET page runs under the identity of a user account with certain permissions. Under IIS 5.1, this account is "ASPNET". Under IIS 6.0 or later, this account is "Network Service" and belongs to an Windows user group called IIS_WPG(" worker process group "). In order to use the Access database under IIS, these accounts must grant permission to read from the directory containing the MDB files and to write as appropriate.

To help you create these licenses, when the database is in the App_Data subdirectory under the root of the application, VWD performs additional steps and automatically grants the license to the ASPNET or Network Service accounts. If you are using VWD to develop pages on your machine, this particular directory will always be granted the correct license. The App_Data directory has additional benefits, such as preventing any files in it from responding to the Web browser that made the request. This means that once the MDB files are placed in the local App_Data directory of the application, they can be protected from being inadvertently or intentionally downloaded by the application's clients. Therefore, it is highly recommended to save the MDB files in the App_Data directory.

If you must save the MDB file somewhere else, or if you need to manually specify the license for the database directory (for example, if you are working on a remote Web server), you can use Windows to configure the license for the ASP.NET and/or Network Service accounts.

To manually set permissions, follow these steps:

(1) browse the MDB folder using Windows Explorer.

(2) right-click the directory and select Properties.

(3) select the Security label and click the Add button.

(4) add a local ASP.NET account (IIS 5.1) or IIS_WPG group (IIS 6).

(5) click OK; Then apply the relevant license to this directory.

If you want to get more information, please refer to the called "Running ASP. 1.1 and 6.0" IIS NET white paper from ASP. NET Web sites: http: / / www asp. net/faq/AspNetAndIIS6 aspx on the white paper.

 


Related articles: