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 upload controls using file files in .NET

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

Share

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

This article mainly explains "how to use the .NET file file upload control". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the .NET file file upload control".

Modify the Webcong file:

The following is the referenced content:

The copy code is as follows:

Among them, what is closely related to upload is:

The copy code is as follows:

MaxRequestLength

Indicates the maximum file upload size supported by ASP.NET.

This restriction can be used to prevent a denial of service attack caused by a user passing a large number of files to the server.

The specified size is in KB.

The default value is 4096 KB (4 MB).

The copy code is as follows:

ExecutionTimeout

Indicates the maximum number of seconds that a request is allowed to execute before it is automatically turned off by ASP.NET.

In seconds, make this larger when uploading large files.

If the server has 512m of memory, you can upload a file with a size of 160m. (no, the consensus of all posts on csdn.)

At this point, the setup of web.config is over.

However, once the size of the uploaded file exceeds the file size range set by this setting, the following error occurs: the page cannot show that the page you want to view is currently unavailable. The site may encounter technical problems, or you may need to adjust your browser settings.

Although it can not be solved, it is also necessary to catch this error! What should I do? Because this error is a foreground error caused by the file control, it is not feasible to use try...catch to catch it in the background.

So I came up with the mechanism of using .NET error trapping page to deal with it. It works.

The following is the referenced content:

1. Set web.config first

The copy code is as follows:

2. Create a new error.aspx file that is specially used to catch errors.

3. Add the page instruction to the foreground page of the aspx page where the file is uploaded. ErrorPage= "UploadError.aspx"

4. Add some code to error.aspx to determine whether the error message is a foreground error caused by file.

The copy code is as follows:

Public class UploadError: System.Web.UI.Page

{

Private void Page_Load (object sender, System.EventArgs e)

{

Exception ex = Server.GetLastError ()

If (ex! = null)

{

Response.Redirect (".. / error.aspx")

}

Else / / foreground error ex is null

{

Response.Redirect ("uploadexcel.aspx?err=1"); / / redirect to the upload page

The err parameter is added to display the error message

}

}

5. Display the error message.

The copy code is as follows:

Public class uploadexcel: System.Web.UI.Page

{

Private void Page_Load (object sender, System.EventArgs e)

{

If (Request ["err"] = = "1")

{

Page.RegisterStartupScript ("budget", "

Alert ('Upload file has failed! File size is too large!')

}

}

}

Thank you for your reading, the above is the content of "how to use .NET file file upload control". After the study of this article, I believe you have a deeper understanding of how to use .NET file file upload control, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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