Fragmented records of Asp.net knowledge and experience,

Source: Internet
Author: User

Fragmented records of Asp.net knowledge and experience,

1. webRestrictions on the size of files uploaded on the front-end page

1.1 configure the size limit of the uploaded files through Web. Config (this applies to site security issues and is carefully configured !!!).

<System. webServer> <security> <requestFiltering> <requestLimits maxQueryString = "10240" maxAllowedContentLength = "2147483647"/> <! -2 GB --> </requestFiltering> </security> </system. webServer>

1.2 use the C # code in the background to restrict the size of uploaded files.

/* Determine whether the size of the uploaded file exceeds the limit */public bool isOutFileSizeLimit (System. web. httpContext context, int nFileSize) {if (context. request. contentLength> nFileSize) {return true; // exceeds the limit} else {return false; // not exceeds the limit }}

The above two methods can meet different needs, and are not alternative solutions. The beginner's conclusion is that readers are also expected to identify and use it on their own.

2. Application of. net Thread Pool

1 using System. threading; 2 3 namespace Threading_Test.Test 4 {5 /// <summary> 6 // encapsulation of thread pool processing function input parameter classes 7 /// </summary> 8 internal class SynDataParam 9 {10 public bool bIsSysData; // identify 11 public string sFolderPath; // ftp path 12 public string sFolderPath_Tk; // ftp path tk13 14 /// <summary> 15 /// constructor 16 /// </summary> 17 /// <param name = "p_bIsSysData"> identifier </param> 18 // <param name = "p_sFolderPath"> ftp path </param> 19 // <param name = "p_sFolderPath_Tk"> ftp path tk </param> 20 public SynDataParam (bool p_bIsSysData, string p_sFolderPath, string p_sFolderPath_Tk) 21 {22 bIsSysData = p_bIsSysData; 23 sFolderPath = p_sFolderPath; 24 sFolderPath_Tk = primary; 25} 26} 27 28 public class Test29 {30 public void main () 31 {32 ThreadPool. queueUserWorkItem (new WaitCallback (this. synDataToTiKu), new SynDataParam (true, maid, "123 ")); 33} 34 35 // <summary> 36 // 37 // </summary> 38 // <param name = "state"> input a parameter of the SynDataParam type </param> 39 public void SynDataToTiKu (Object state) 40 {41 SynDataParam = state as SynDataParam; 42 43 if (SynDataParam. bIsSysData) 44 {45 46} 47} 48 49} 50}

3. web service call

Using System; using System. collections. generic; using System. linq; using System. text; using System. web; using System. IO; using System. web. configuration; using System. net;
Namespace yu. zhi. hui {internal class GetOrSetDataHelper {/*** the http post method of the web service calls *** /// <summary> // to obtain the result (this method mainly obtains the PostUrl and then call GetPostRequest) /// </summary> /// <param name = "sQueryStr"> interface input parameters, such: sLevel = string & sFormat = string </param> // <param name = "interfaceName"> The Method name of the interface to be called </param> // <returns> returns interface return value </returns> public string GetOrSetDataByWsWithHttpPost (string sQueryStr, string interfaceName, string sWsPath) {// url of the post call method :" http://xxx.xxx.xx.xx:xxxx/xxxx.asmx/Get_xxx "String PostUrl = sWsPath +"/"+ interfaceName; byte [] data = Encoding. UTF8.GetBytes (sQueryStr. toString (); string resCode = GetPostRequest (data, PostUrl); return resCode ;} /// <summary> // call the ws interface in Http Post mode -- send request data and obtain response data // </summary> /// <param name = "data"> </param> /// <param name = "url"> </param> // <returns> </returns> private string GetPostRequest (byte [] data, string url) {try {// create a request HttpWebRequest myRequest = (HttpWebRequest) WebRequest. create (url); // The complete request address (ip: Port Number/+ url) myRequest. method = "POST"; myRequest. contentType = "application/x-www-form-urlencoded"; myRequest. accept = "text/xml"; myRequest. headers. add ("SOAPAction", url); // whether to send myRequest together with the request. usedefacrecredentials = true; myRequest. contentLength = data. length; // create input Stream newStream = myRequest. getRequestStream (); // Send the request to Send the data. newStream. write (data, 0, data. length); newStream. close ();/*-request end-* // *-response begin-* // create response Get response var response = (HttpWebResponse) myRequest. getResponse (); using (var reader = new StreamReader (response. getResponseStream (), Encoding. getEncoding ("UTF-8") {// read response string result = reader. readToEnd (); reader. close (); response. close (); return result ;}} catch (Exception ex) {return ex. toString ();}}}}

 

Updating later. Please wait...

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.