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

What is the hidden trouble in the operation of ASP.NET virtual host file system?

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

Share

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

This article introduces the knowledge of "ASP.NET virtual host file system operation hidden danger". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

ASP.NET virtual hosting file system manipulation pitfalls before we write code, it is necessary to understand we need to use a few major classes. These classes are all under the System.IO namespace, which contains classes that allow synchronous and asynchronous reads and writes on data streams and files.

At the beginning of the whole application we need to understand the system information of the server, which requires the use of the System.Environment class, which provides information about the current environment and platform and how to operate them. We can get the current directory of the system and the system directory through the System.Environment class, which allows us to find several key directories faster; we can also help us understand the user used by ASP.NET programs by getting the user name of the current process, and further setting user permissions to avoid this security problem.

A few other classes that we will also use the System.IO namespace are:

System.IO.Directory: A class that provides static methods for creating, moving, and enumerating through directories and subdirectories

System.IO.File: Class that provides static methods for creating, copying, deleting, moving, and opening files

System.IO.FileInfo: Class that provides instance methods for creating, copying, deleting, moving, and opening files

System.IO.StreamReader: Implement a TextReader that reads characters from a byte stream in a specific encoding.

The properties and methods of each class we use are explained in code comments.

The System.IO namespace is in mscorlib.dll provided by. NET FRAMEWORK, and this Dll needs to be referenced in this project before programming with VS.Net.

The programs we wrote all use the Codebehind method, that is, each aspx program has a corresponding aspx.cs program, aspx program only writes code related to page display, all logic implementation code is placed in the corresponding aspx.cs file, so that it can be better to achieve the separation of display and logic. Since our purpose is not to discuss Codebehind technology, we will not discuss it further.

In this article, we'll cover only a few of the main classes and the usage of their key methods. Please check the accompanying source code for details.

Program one: listdrivers.aspx program that displays current information about the server and the names of all logical drives

Main Method 1: We use GetSysInf() to get information about the server's current environment and platform

//Method to obtain system information. This method is public void GetSysInf () in listdrivers.aspx.cs file { //Obtain operating system type qDrives = Environment.OSVersion.ToString(); //Obtain system folder qSystemDir = Environment.SystemDirectory.ToString();/* Get the amount of physical memory mapped to the process context. Through this memory mapping amount, you can know how much system physical memory is needed when the ASP.NET program is running, which is helpful for better planning of our entire application. Because the amount of physical memory is in Byte, we divide this value by 1024 to get the amount of physical memory in KB */ qMo =(Environment.WorkingSet/1024).ToString(); //Get the fully qualified path of the current directory (i.e., the directory from which the process started) qCurDir = Environment.CurrentDirectory.ToString(); //Get the network domain name of the host qDomName = Environment.UserDomainName.ToString(); //Get the number of milliseconds elapsed since the system started qTick = Environment.TickCount; //Calculate the elapsed minutes qTick /= 60000; //Get the machine name qMachine = Environment.MachineName; //Get the user name qUser = Environment.UserName; /* Retrieves the name of logical drives in the format "Drive letter>:\" on this computer and returns a string array, which is the key to the next operation */ achDrives = Directory.GetLogicalDrives();//Get the dimensions of this string array, determine how many logical drives nNumOfDrives = achDrives.Length; }

ASP.NET virtual host file system operation hidden dangers in the system information does not need to be operated, we simply use asp:Label to show them on the line. The number of logical drives is variable on different servers, so we use an array of variable lengths to save the names of logical drives, and the names of logical drives are also the basis for our next browsing of directories and files, so we use DataGrid to display and process it.

The DataGrid code for displaying and processing logical drive names (code in listdrivers.aspx file):

DataNavigateUrlField="Drivers" DataNavigateUrlFormatString="listdir.aspx? dir={0}" DataTextField="Detail" Target="_new" /﹥ ﹤/Columns﹥ ﹤/asp:DataGrid﹥

The first two BoundColumn columns display the serial number and the actual logical drive name. What needs to be explained is the third column. Before entering the display directory and file of each logical drive, we need to pass the name of the selected logical drive to the file of the display directory. Therefore, we need a special hyperlink line HyperLinkColumn. We set DataNavigateUrlField to the field of the URL to be bound to the hyperlink in HyperLinkColumn in the data source, which is the logical drive name here. DataNavigateUrlFormatString is then set to the display format of the URL of the hyperlink in this HyperLinkColumn when URL data is bound to a field in the data source, i.e. the next level of processing page to link to, here listdir.aspx? dir={logical drive name of user-clicked row}

"ASP.NET virtual host file system operation hidden trouble is what" the content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

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