With Asp/asp. NET to realize network space management

Source: Internet
Author: User
Tags file size file upload ftp mail reference
Preface of Asp.net| Network

⑴ electronic reading Room, computer rooms, Internet cafes and other public places due to the use of frequent, maintenance lag, such as the output system such as floppy disk damage is common, often in the data you need to be processed after the output of the output device can not work and greatly irritated, and many computer rooms in order to save costs, It is not equipped with a fully-needed output device on a networked computer.

⑵ computer popularization at the same time make people rely on it more and more strong, a lot of office business has been inseparable from the computer. In other words, office computers start to store a lot of important office and private data. These data, in most cases, are unique, meaning that their owners do not keep a copy of them on different computers, and their security depends entirely on the stability of their owners ' computers.

The popularization of ⑶internet has narrowed the distance between people, so that people communicate more convenient, but we need every day in the home, office, internet cafes and other places to surf the internet, how can we continue to edit a document to deal with it? Perhaps through a USB drive or a mobile hard disk, such as mobile storage devices can carry this information, but carry more than one such device, especially the mobile hard drive is not very convenient, and different places, different devices, different operating systems for USB or mobile hard disk support is not the same, The user's computer level is also different.

......

Due to these facts, the networked storage as a need to board the stage.

There are many ways to implement networked storage today, such as e-mail, FTP, Network Places, HTTP, and so on. Among them, FTP is the most powerful, but slightly more complex to use, a large set of settings enough to make many people Shing, especially when the number of users unpredictable, for special needs of the user's settings will be more cumbersome; e-mail is familiar to everyone, but within the local area network, finance, It is not a good idea to exchange documents and information in such a way, and, when your files are big enough, it's a fatal shock to the mail space; Network Places can access these files by specifying shared Web folders on the local computer and placing them in a range of users, but the scope of this approach is quite limited. It is common for users in the same DNS segment address to be able to access them smoothly, others, especially on the Internet, are difficult to use, and similar to e-mail, it is not intuitive to use, many times you have to be on many list computers on a layer of search to get the resources you want! One common drawback of these networked storage approaches is that administrators cannot have a clearer understanding of the use of files stored in networked storage and can only decide whether or not to clean them up based on how long they are stored.

This article describes a relatively simple way of networked storage via HTTP. This is done through IIS with asp/asp on the Windows platform. NET to achieve, not only the use of simple, can upload any type of file, and can use space for the user limit, one transmission to 20 bytes, large to hundreds of trillion can be managed by the manager, in addition, the security of the file is also protected, only the file owner and the authorized person can return the file. Read the second big point in the data structure and the third big point of the upload source code, will help you do a network storage, you do not have to rely on the market to provide free network storage, so that the network internal sensitive data file security firmly in their hands.

Overview and basic functionality

Install a server as a network storage host, the operating system using Windows platform, supporting IIS5.0, set up a Web service, in the main site to establish a virtual Web site, pointing to networked storage, such as: D:\netspace\spacenet\myspace. All the ASP and ASP.net source code placed in the main site (such as: C:\inetpub\wwwroot), under the D:\netspace\spacenet\myspace will put the user uploaded files (virtual site changes, in the source code should also be adjusted accordingly).

1, the use of the basic database and structure:

⑴ftpsapce.mdb: Own table userlist, table basic structure:

Id: Sequence number, automatic generation;
Xh: User account, registration and validation generation;
Xm: User name, registration and validation generation;
Kl: User password, registration and validation generation;
Maxspace: User space maximum limit, register to take default value, admin can reset by admin;
Nowspace: The amount of space currently occupied by the user;
Lastaccessday: User's most recent access time, for administrators to manage space for reference;
Fromday: User registration time;
Checkx: User verifies no flags.

⑵filelist.mdb: Own table files, table basic structure:

Id: Sequence number, automatic generation;
FileName: File name, upload system to judge the generation;
Fsize: File size value;
Xh: User account;
Upday: Upload time;
Filescript: File Description, is the user upload the file path and the original filename, for users to load reference;

2. Basic function

⑴ users login to the main site, access to the homepage of the site, give users the basic information for user registration.

⑵ Administrator According to user registration data to be audited, set user maximum use space.

⑶ audit through the user upload files to networked storage. The system determines the legality of the user and the legality of the documents, and registers the files and user data uploaded by the user in the database.

⑷ audited users to upload their own files to download or delete.

The ⑸ administrator manages the network space according to the user database and the file database.

The ⑹ extended system allows authorized users to download uploaded files for authorized users.

Upload Module Basic source code

Limited to space, this article only gives the upload module of the basic source code, need more source code can be obtained by e-mail to the author, the source code in the first line of the * * * is the author for readers to read convenient and added comments. (The following excerpt from upfile.aspx)

<%@ Page language= "VB" debug= "true"%>
<%@ import namespace= "System.Data"%>
<%@ import namespace= "System.Data.oledb"%>
<script language= "VBScript" runat= "Server"
Sub UploadFile (sender As Object, E as EventArgs)
If fileup.postedfile.contentlength<20 Then
Errors.text= "Such a small file to upload, back on it."
Fileinfo.visible=false
Exit Sub
Else
errors.text= "Normal Test"
Fileinfo.visible=true
End If

Above check upload file size
respace.text= "0"
nowspace.text= "0"

Respace refers to the remaining space, nowspace refers to the used space

Dim xh1 As String =user1.value
Dim kl1 As String =pass1.value

Xh1 refers to the account number, KL1 refers to the password

Dim objconnstr As String= "Provider=Microsoft.Jet.OLEDB.4.0;Data source="
& Server.MapPath ("Ftpspace.mdb")

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

Dim objconn As OleDbConnection = new OleDbConnection (OBJCONNSTR)
Dim sql1 As String= "select * from userlist where xh= '" +xh1+ "' and Kl= '" ""
Dim objrscc As Oledbcommand= New OleDbCommand (Sql1,objconn)
objConn.Open ()
Dim objRS As OleDbDataReader = Objrscc.executereader ()
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

The above decision account number and password is legal

If Ix<=0 Then
errors.text= "account password wrong!" Or the user has not passed the authentication, please wait for the Administrator authentication! "
Else

If Fileup.postedfile.contentlength>maxs-nows Then
If Fileup.postedfile.contentlength>=maxs Then
errors.text= "file length is greater than the size of the given space, cannot upload!" "
Else
errors.text= "free space is insufficient, please delete old file!" "
End If

The above determines the availability of user space
Else
Dim obj4str As String= "provider=microsoft.jet.oledb.4.0;
Data source= "& Server.MapPath (" Filelist.mdb ")

The above two lines in the source code for the same statement
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)

Above a unique main file name for uploading files to the user
Dim objc1str As String= "provider=microsoft.jet.oledb.4.0;
Data source= "& Server.MapPath (" Filelist.mdb ")

The above two lines in the source code for the same statement
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 in the source code for the same statement
Objc1.open ()
Dim objrs1 As Oledbcommand=new OleDbCommand (SQL3,OBJC1)
Dim fn2 As String
Fn2= "d:/netspace/spacenet/myspace/" &cstr (FN1) & ". zip"

gives the absolute path and full file name of the user's uploaded file
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 xh= '" +xh1+ ""

The above two lines in the source code for the same statement

Dim objrnc As Oledbcommand= New OleDbCommand (Sql5,objconn)
Objrnc.executenonquery ()
Respace.text=cstr (maxs-nows-fileup.postedfile.contentlength) & "bytes."
Nowspace.text=cstr (nows+fileup.postedfile.contentlength) & "bytes."

The above upload action, and calculate the user's total space and the remaining total space
End If
End If
End Sub
</script>
<body>
<form enctype= "Multipart/form-data" runat= "Server"
<table>
<tr> <td> Account Number: </td> <td> <input id= "user1" runat= "server" > </td> </tr>
<tr> <td> Password: </td> <td> <input type= "password" id= "Pass1" runat= "server" > </td> </tr>
<tr> <td> file: </td> <td> <input type= "file" id= "Fileup" runat= "server" > </td> </tr>
<tr> <td> </td> <td> <asp:button id= "upload" text= "upload"
runat= "Server"/> </td> </tr>
</table>
</form> <div id= "FileInfo" visible= "false" runat= "Server"
Original filename: <asp:label id= "fname" runat= "Server"/> <br>
Byte size: <asp:label id= "fsize" runat= "Server"/> <br>
File type: <asp:label id= "ftype" runat= "Server"/> <br>
User account: <asp:label id= "username" runat= "server"/> <br>
Remaining space: <asp:label id= "Respace" runat= "Server"/> <br>
Used space: <asp:label id= "Nowspace" runat= "Server"/> <br>
Upload status: <asp:label id= "Errors" runat= "Server"/>
</div>
Above in the browser to tell users before and after the file upload relevant information
</body>
Conclusion

The method described in this article is based on the component-free technology, the security of the file and personal privacy considerations, the most suitable for Windows Server 2003 with the IIS6.0 platform to use, the method is simple and secure, slightly expanded, such as in the UserList Add user number, group number, In the files to add a group number, you can set the permissions of the file to facilitate the implementation of file network submission, verification, sharing. With the disk array, there will be a qualitative improvement in data security.


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.