Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the hidden trouble of ASP.NET virtual host in file directory management

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces you how to analyze the hidden dangers of ASP.NET virtual host in file directory management, the content is very detailed, interested friends can refer to, hope to be helpful to you.

What is the hidden danger of ASP.NET virtual host in file directory management? First, let's look at an example of the program listdir.aspx that shows all the subdirectories and files in the directory

There are two forms of subdirectories and files under the directory, which must be treated separately. We call the program itself to display the list of subdirectories, and we need to call the showfile.aspx program to display the properties and contents of the file. And the two have different deletion methods, so we set up two DataGrid, two DataTable, and two DataView here to process and display directories and files respectively.

ASP.NET virtual host displays and processes the DataGrid code for directories and files during file directory management (the code is in the listdir.aspx file):

The data column showing the serial number and name of the directory or file is similar to the corresponding code in the listdrivers.aspx program, so I won't repeat it here. There are separate processing pages for subdirectories and files, so you need to navigate to two different pages. For subdirectories, we continue to use the listdir.aspx program to list the subdirectories and files under them:

< asp:HyperLinkColumn DataNavigateUrlField= "DirName" DataNavigateUrlFormatString= "listdir.aspx?dir= {0}" DataTextField= "DirDetail" HeaderText= "details" Target= "_ new" / >

For files, we use the showfile.aspx program to display their properties and contents:

< asp:HyperLinkColumn DataNavigateUrlField= "FileName" DataNavigateUrlFormatString= "showfile.aspx?file= {0}" DataTextField= "FileDetail" HeaderText= "details" Target= "_ new" / >

In the two DataGrid (DirGrid,FileGrid), we set up two HyperLinkColumn columns to navigate to different processing pages.

The ASP.NET virtual host uses a deleted button column in both DataGrid when managing the file directory:

< asp:ButtonColumn HeaderText= "Delete" Text= "Delete" CommandName= "Delete" / >

Since the add, update, and delete function columns are all default template columns for DataGrid, you can automatically add this column in Vs.net through DataGrid's property generator.

Get the code for the parameters passed on the previous page:

Because the following method of generating the data source needs to use the parameters passed from the previous page to determine the name of the directory and file, the following code is used in the page's Page_Load method:

StrDir2List = Request.QueryString ["dir"]

The string strDir2List is the name of the directory or file passed in.

Because we use two DateGrid and need to do two data bindings, there are two different ways to generate the data source.

The method of generating catalog data grid (DirGrid) data sources:

/ / return a data view DataView in the form of a collection through this method, which is used to initialize the DataGrid ICollection CreateDataSourceDir () {dtDir = new DataTable () of the subdirectory; DataRow dr; / / adds a new data column to DataTable with a total of four columns of dtDir.Columns.Add (new DataColumn ("DirID", typeof (Int32)); dtDir.Columns.Add (new DataColumn ("DirName", typeof (string); dtDir.Columns.Add (new DataColumn ("DelDir", typeof (string) DtDir.Columns.Add (new DataColumn ("DirDetail", typeof (string); / / get the string array string [] DirEntries = Directory.GetDirectories (strDir2List) of all subdirectory names under this directory according to the passed parameter (directory name); / / use the foreach loop to iterate through the array of unknown length foreach (string DirName in DirEntries) {dr = dtDir.NewRow (); dr [0] = I Erique / serial number dr [1] = DirName / / folder name dr [3] = "delete"; dr [3] = "View details"; dtDir.Rows.Add (dr); iTunes;} DataView dvDir = new DataView (dtDir); / / returned data View return dvDir;}

The method for ASP.NET virtual hosts to generate file data grid (FileGrid) data sources during file directory management:

/ / return a data view DataView in the form of a collection through this method, which is used to initialize the file's DataGrid ICollection CreateDataSourceFile () {dtFile = new DataTable (); DataRow dr; dtFile.Columns.Add (new DataColumn ("FileID", typeof (Int32); dtFile.Columns.Add (new DataColumn ("FileName", typeof (string); dtFile.Columns.Add (new DataColumn ("DelFile", typeof (string) DtFile.Columns.Add (new DataColumn ("FileDetail", typeof (string); / / get the string array string [] FileEntries = Directory.GetFiles (strDir2List) of all filenames under this directory based on the passed parameters (directory name); foreach (string FileName in FileEntries) {dr = dtFile.NewRow (); dr [0] = I; dr [1] = FileName; dr [2] = "delete"; dr [3] = "View details" DtFile.Rows.Add (dr); iTunes;} dvFile = new DataView (dtFile); return dvFile;}

We programmed to realize that two DataSource only need to bind two DataGrid in the Page_Load method of the page to display the data in the DataTable on the DataGrid of the aspx page.

Data binding code:

/ / data source definition and data binding for subdirectory data list DirGrid DirGrid.DataSource = CreateDataSourceDir (); DirGrid.DataBind (); / / A pair of file data list FileGrid for data source definition and data binding FileGrid.DataSource = CreateDataSourceFile (); FileGrid.DataBind ()

Through the main methods we described above, we have implemented a list display of all subdirectories and files in a logical drive or directory. And you can browse the subdirectories further or view the properties and content feeds of the files according to the display results. Browsing subdirectories is still done through the listdir.aspx program, without any subdirectory level requirements and no directory depth restrictions.

On how to analyze the hidden dangers of ASP.NET virtual host in file directory management is shared here, I hope the above content can be of some help to everyone, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report