Experiences in Asp.net Development

Source: Internet
Author: User

1. Pay special attention to the use of JS files and the aspx file character set.

Under normal circumstances, Asp.net may have character set problems when handling a JS file. Because JS usually adopts the ASCII code method, the Asp.net page is usually UTF-8 or Unicode, so the two sessions suddenly rushed, so pay special attention to it!

2.The memory occupied by Asp.net files is too large.

Use

Fileinfo = new fileinfo (filepath );
Response. Clear ();
Response. clearcontent ();
Response. clearheaders ();
Response. addheader ("content-disposition", "attachment; filename =" +
Filename );

.......

Directly open the file and send the file. This will occupy a lot of memory. The following two methods can be used to alleviate the problem:

The following code controls the buffer size? 1024 bytes should be too small
Byte [] buffer1 = new byte [0x400];
While (num3> 0)
{
Num3 = stream1.read (buffer1, 0, buffer1.length );
Response. outputstream. Write (buffer1, 0, num3 );


 

 

}

Try this.

Private void downfile (string filepath, string filename)
{
Fileinfo = new fileinfo (filepath );
Response. Clear ();
Response. clearcontent ();
Response. clearheaders ();
Response. addheader ("content-disposition", "attachment; filename =" +
Filename );
Response. addheader ("Content-Length", fileinfo. length. tostring ());
Response. addheader ("content-transfer-encoding", "binary ");
Response. contenttype = "application/octet-stream ";
Response. contentencoding = system. Text. encoding. getencoding ("gb2312 ");
Response. writefile (fileinfo. fullname );
Response. Flush ();
Response. End ();

From: http://blueleopard.bokee.com/4954120.html

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.