ASP. NET for network space management

Source: Internet
Author: User

Preface

(1) In public computer places such as electronic reading rooms, computer rooms, and Internet cafes, due to frequent use and lagging maintenance, damage to the output system, such as a soft drive, is common, it is often discovered that the output device cannot work but is very open when you need to output the processed data. In order to save costs, many Computer Rooms, A computer connected to the Internet is not equipped with all necessary output devices.

(2) Computers are becoming more and more reliant on computers, and many office affairs are inseparable from computers. In other words, office workers start to store a lot of important office and private data on their computers. In most cases, the data is unique, meaning that their owners do not store them as copies on different computers, their security depends entirely on the stability of their owner's computer.

(3) the popularity of the Internet has brought people closer to each other and made communication easier. However, we need to access the Internet in different places such as home, office, and Internet cafe every day, how can we continuously edit a document? You may be able to carry this information with you through a USB flash drive or a mobile storage device such as a mobile hard disk. However, it is not very convenient to bring such a device with you, especially a mobile hard disk, in addition, different locations, devices, and operating systems have different support for USB flash drives or mobile hard drives, and the user's computer level is also different.

......

Due to these facts, network storage has become a must.

Currently, there are many network storage methods, such as email, FTP, network neighbors, and HTTP. Among them, FTP is the most powerful, but it is a little complex to use, a lot of settings are enough to let many people stop, especially when the number of users is unpredictable, users with special requirements will be more complicated to set up. emails are familiar to everyone, but it is not a good way to exchange documents such as finance and labor resources within the LAN, in addition, when your files are large enough, it will have a fatal impact on the email space. by specifying the shared Web folder on the local machine and placing the files, users within a certain range can access these files. However, the scope of this method is quite limited. users within the same DNS segment can access these files smoothly, it is difficult for other users, especially those on the Internet, to use it. In addition, it is not intuitive to use like an email, most of the time, you have to expand the search layer by layer on many list computers to obtain the resources you want! The preceding network storage methods share the following Disadvantages: Administrators cannot clearly understand the usage of files stored in network storage, you can only determine whether to clean up a file based on its storage time.

This article introduces a simple network storage method implemented through HTTP. This method is implemented through IIS and ASP/ASP on the WINDOWS platform. NET, not only simple, can upload any type of files, but also can restrict the user's space, management can manage a single transmission of up to 20 bytes and up to several hundred megabytes. In addition, the security of the file is also guaranteed. Only the file owner and the authorized person can upload the file back. Reading the data structure in the second and upload source code in the third node of this article will help you create a network storage, so you do not have to rely on the free network storage provided on the market, this ensures security of sensitive data files in the network.

Overview and basic functions

Install a server that acts as the network storage host. The operating system uses the windows platform and works with IIS5.0. Set up the WEB service and create a virtual website under the main website, pointing to network storage, such as: d: etspacespacenetmyspace. All asp and asp.net source codes are stored on the main website (for example, c: inetpubwwwroot), and d: etspacespacenetmyspace stores user-uploaded files (Virtual websites change, the source code should also be adjusted accordingly ).

1. Basic databases and structures used:

(1) ftpsapce. mdb: Has the userlist table. The basic table structure is as follows:

Id: sequence number, which is automatically generated;
Xh: User Account, registration and verification generation;
Xm: user name, registration and verification generation;
Kl: User Password, registration and verification generation;
Maxspace: The maximum user space limit. The default value is used for registration. The administrator can reset the value through management;
Nowspace: the amount of space currently occupied by users;
Lastaccessday: The last access time of the user for the Administrator to manage the space;
Fromday: user registration time;
Checkx: indicates whether the user has verified the flag.

(2) Filelist. mdb: Has table files. The basic table structure is as follows:

Id: sequence number, which is automatically generated;
Filename: file name, which is generated by the upload system;
Fsize: the file size value;
Xh: User Account;
Upday: Upload time;
Filescript: The file description. It is the path and original file name of the file uploaded by the user for your reference during loading;

2. Basic functions

(1) the user logs on to the main website, enters the homepage of the website, and provides basic user information for user registration.

(2) The Administrator should review the User Registration Information and set the maximum user space.

(3) users who pass the review upload files to network storage. The system determines the validity of users and files, and registers the files uploaded by users and user data in the database.

(4) users who have reviewed the download function can upload or delete the files they have uploaded.

Administrators manage network spaces based on user databases and file databases.

The extended upload system allows authorized users to download uploaded files from authorized users.

Upload module basic source code

Limited by space, this article only provides the basic source code of the upload module. For more source code, you can obtain it from the author via E-mail, the lines starting with *** in the source code are comments that the author adds for the convenience of reading. (See upfile. aspx below)

<% @ Page Language = "VB" Debug = "true" %>
<% @ Import namespace = "System. Data" %>
<% @ Import namespace = "System. Data. oledb" %>
<Html>
<Script language = "vbscript" runat = "server">
Sub previusfile (sender as object, e as eventargs)
If fileup. postedfile. contentlength <20 then
Errors. text = "this small file also needs to be uploaded and backed up ."
Fileinfo. visible = false
Exit sub
Else
Errors. text = "Check normal"
Fileinfo. visible = true
End if

*** Check the size of the uploaded file
Respace. text = "0"
Nowspace. text = "0"

* ** Respace indicates the remaining space, and nowspace indicates the used space.

Dim xh1 as string = user1.value
Dim kl1 as string = pass1.value

* ** Xh1 indicates the account and kl1 indicates the password.

Dim objconnstr as string = "provider = microsoft. jet. oledb.4.0; data source ="
& Server. mappath ("ftpspace. mdb ")

* ** The above two lines should be the same statement in the source code.

Dim objconn as oledbconnection = new oledbconnection (objconnstr)
Dim sql1 as string = "select * from userlist where xh =" + xh1 + "and kl =" + kl1 + ""
Dim objrscc as oledbcommand = new oledbcommand (sql1, objconn)
Objconn. open ()
Dim objrs as oledbdatareader = objrscc.exe cutereader ()
Dim ix as integer = 0
Dim maxs as long
Dim nows as long
While ix = 0
If objrs. read () then
If objrs. item ("xh") = xh1 then
If objrs. item ("kl") = kl1 then
If objrs. item ("checkx") = 1 then
Ix = ix + 1
Maxs = objrs. item ("maxspace ")
Nows = objrs. item ("nowspace ")
End if
End if
End if
Else
Ix =-1
End if
End while

*** Determine whether the account and password are valid

If ix <= 0 then
Errors. text = "the account password is incorrect! Or the user has not passed the authentication. Please wait for administrator authentication! "
Else

If fileup. postedfile. contentlength> maxs-nows then
If fileup. postedfile. contentlength> = maxs then
Errors. text = "the file length is greater than the given space and cannot be uploaded! "
Else
Errors. text = "the available space is insufficient. please delete the old file! "
End if

*** Determine the availability of the user space
Else
Dim obj4str as string = "provider = microsoft. jet. oledb.4.0;
Data source = "& server. mappath (" filelist. mdb ")

* ** The above two lines are the same statement in the source code.
Dim obj4 as oledbconnection = new oledbconnection (obj4str)
Dim sql10 as string = "select * from files"
Dim objrc1 as oledbcommand = new oledbcommand (sql10, obj4)
Obj4.open ()
Dim objrsx as oledbdatareader = objrc1.executereader ()
Dim fn11 as long = 0
While objrsx. read ()
Fn11 = objrsx ("filename ")
End while
Dim fn1 as string
Fn1 = cstr (fn11 + 1)

*** The above indicates a unique primary file name for the user to upload the file.
Dim objc1str as string = "provider = microsoft. jet. oledb.4.0;
Data source = "& server. mappath (" filelist. mdb ")

* ** The above two lines are the same statement in the source code.
Dim objc1 as oledbconnection = new oledbconnection (objc1str)
Dim sql3 as string = "insert into files (filename, fsize, xh, filescript, upday)
Values ("+ cstr (fn1) +", "+ cstr (fileup. postedfile. contentlength) + ","
+ Xh1 + "," + fileup. postedfile. filename + "," + cstr (now () + ")"

* ** The above three lines are the same statement in the source code.
Objc1.open ()
Dim objrs1 as oledbcommand = new oledbcommand (sql3, objc1)
Dim fn2 as string
Fn2 = "d:/netspace/spacenet/myspace/" & cstr (fn1) & ". zip"

* ** The absolute path and complete file name of the uploaded file are provided.
Fsize. text = cstr (fileup. postedfile. contentlength)
Ftype. text = fileup. postedfile. contenttype
Fname. text = fileup. postedfile. filename
Username. text = user1.value
Fileup. postedfile. saveas (fn2)
Objrs1.ExecuteNonQuery ()
Objrs. close
Dim sql5 as string = "update userlist set nowspace =" + cstr (nows + fileup. postedfile. contentlength) +
", Lastaccessday =" + cstr (now () + "where x

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.