文件发布问题 - ASP.Net

时间:2011-09-08 07:00:31

标签: asp.net

我必须使用名为uploadFile的Web服务方法。该方法将参数作为base64str获取并将其作为文件记录到指定的地址中。   但是,我有一个问题。这个方法不允许上传超过350 KB的文件。否则,我可以上传少于300 KB的文件,例如zip,jpg,txt。也,   当我尝试上传超过350 KB的文件时,一个进程在服务器上不断工作。

过程:

Image Name : w3wp.exe, UserName : ASP.Net v4.0, CPU : 50, Description : IIS Worker Process

有时服务器cpu会达到100%

代码:

  * encodedFile = Base64Str as format

    string postString = string.Format("userName={0}&userVendor={1}&vendorKey={2}&base64FileStr={3}&guid={4}&fileName={5}",                                 "kadi", "şifre", "key", encodedFile, guid, strFilename);


                string localHttpPostUrl = userGatewayAddress + "uploadFile";

                ASCIIEncoding encoding = new ASCIIEncoding();

                Stream newStream = null;

                HttpWebResponse response = null;

                Stream streamResponse = null;

                StreamReader streamRead = null;


               try

                {

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(localHttpPostUrl);

                    request.ContentType = "application/x-www-form-urlencoded";

                    request.Method = "POST";



                    byte[] buffer = Encoding.UTF8.GetBytes(postString);

                    request.ContentLength = buffer.Length;


                    newStream = request.GetRequestStream();

                    newStream.Write(buffer, 0, buffer.Length);

                    newStream.Close();


                    response = (HttpWebResponse)request.GetResponse();

                    streamResponse = response.GetResponseStream();

                    streamRead = new StreamReader(streamResponse);


                    Char[] readBuffer = new Char[256];

                    ret = string.Empty;

                    int totalCharCount = 0; 

                    int count = streamRead.Read(readBuffer, 0, 256);

                    while (count > 0)

                    {

                        totalCharCount += count;

                        ret += new String(readBuffer);

                        count = streamRead.Read(readBuffer, 0, 256);

                    }

                    ret = ret.Substring(0, totalCharCount);


                    return ret;

                }

                catch (Exception x)

                {

                    return x.Message;

                }

1 个答案:

答案 0 :(得分:1)

<system.web>
   <!-- 100 KB Max POST size -->
   <httpRuntime maxRequestLength="100"/>
</system.web>

http://support.microsoft.com/kb/832878