ASP.NET ??? ??? ??? ????? ?? ??? ????? C# .NET ?? ????? ?? ??? ????? ????? ???? ?? ??? ???? ????

???? ?????? ???? ??????
???? ID: 323246 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

?? ??? ?? ??? ???? ????? ???? ?? ?? ????? C# .NET ?? ????? ?? ???? ??? ????? ?? ??? ?? ????? ????? ???? ?? ??? ???? ????? ?? ???? ??? ?? ????? Microsoft asp.NET ????? (WebForm1.aspx) ?? ???? ??????? ???-behind ???? ?? ???? ?????????? ?? ??? ???? ??????? ????? ???? ?? ??? (WebForm1.aspx.cs)?


ASP.NET ????????? ?????

Microsoft Visual Studio .NET, ??? ??? ????? ?? ??????? ????? ???? ?? ??? ???? ?? ????????? ????? ?? ???, ????? ????? ?? ???? ????:
  1. Microsoft Visual Studio .NET ???? ????..
  2. ????? ???????????? ??,????? ????-????? ????, ?? ???? ????????????.
  3. ???????? ?????????????? ????? ???, ????? ????????? C# ??????????? ???????????????? ???????? ????-????? ????, ?? ???? ???ASP.NET ??? ??????????? ???????????????.
  4. ???????????????, ????????? ????? ?? ??? URL ???? ????? ?? ?????? ?? ??? ?????HTTP://localhost/CSharpUpload, ?? CSharpUpload ?? ??????? ????????? ??? ????? ??? ????? ??? ?? Visual Studio .NET ?? ??????? ????? ??? WebForm1.aspx ???? ??? ?? ???? ???

???? ?????????? ?????

?? ????????? ?? ????? ???, ?? ??? ?? ???? ?????????? uploaded ??????? ?? ??????? ?????? ????? ???? ???? ?? ?????????? ?????, ?? ??? ???? ASPNET ????? ???? ?? ??? ???? ????????? ?? ??? ???? ?????
  1. Visual Studio .NET ?? ?????? Explorer ?????, ??? ???? ?????CSharpUpload?? ????? ????,add?? ????-????? ????, ?? ???? ?????? ???????. ???????? ??? ??, NewFolder1 ??? ?? ?? ??? ??????? ????? ???
  2. ???? ?? ??????? ??? ?? ????? ?? ??? ???? ?????NewFolder1????? ????,??? ?????, ?? ??? ???? ????????:.
  3. Windows Explorer ??????? ????, ?? ?? ???? ????? ?????? ??????? ?? ?????? ????? ?? ???? ??? 2 ??? ????? ??? ???????? ??? ??, ?? ??????? ????? ??????? ??? ????? ??:
    C:\Inetpub\wwwroot\CSharpUpload\Data
  4. ???? ?????????? ?? ??? ???? ?? ?????? ???? ???? ?? ??? ??????? ???????? ?? ????????? ???? ?? ??? ???? ?????????:?? ????-????? ????, ?? ???? ??????.
  5. ????????? ???????? ????? ???, ????? ?????????????? ????? ????, ?? ???? ???add.
  6. ??????????????? ?? ???? ?? ??? ????????? ????? ???, ????? ????ASPNET????, ?? ???? ???add. ????? ????,OK??? ???? ?? ????????????? ?? ???? ?? ??? ????????? ????? ?? ??????? ?? ??? ?? ..
  7. ????? ????aspnet_wp ???? (computername\ASPNET)???? ??, ?? ???? ??? ?? ??? ???? ?? ??? ????? ?????????? ???????? ????????? ?? ??? ????? ??? ????:

    • ????? ?? ????????
    • ??????? ??????? ?? ???????? ????
    • ????
    • ????

    ???? ?? ???? ?? ???? ???? ?? ??? ????? ?????????? ???, ????????????????? ??? ?????
  8. ????? ????,OK??? ???? ?? ??????? ???????? ????? ?? ??????? ?? ??? ?? .. ?? ??????????? ????? ??? ?????????? ?????? ?? ??????? ???? ?? ??? ???? ??????????? ????????? ?? ??????? ???

WebForm1.aspx ????? ?? ??????? ????

??????? ????? ???? ?? ??? ???????????? ?? ?????? ???? ?? ??? WebForm1.aspx ????? ?? HTML ??? ?? ??????? ???? ?? ??? ????? ????? ?? ???? ????:
  1. Visual Studio .NET ?? ???? ?????? ?? ??? ???? ??? ??? WebForm1.aspx ??????? ????? ??? ???? ???? ??????
  2. WebForm1.aspx ??? ?? HTML ????? ?? ????? ?? ??? ???? ?????WebForm1.aspx??????? ?????, ?? ???? ???HTML ????? ?????.
  3. ????? HTML ???, ?????? ?? ?????? ?????<form>???:
    <form id="Form1" method="post" runat="server">
    					
  4. ?????enctype "?????????/???????-????" =???? ?? ??? ???-??? ???????<form>??? ?? ??? ???:
    <form id="Form1" method="post" enctype="multipart/form-data" runat="server">
    					
  5. ????? ?? ???<form>??? ?? ???, ????? ??? ??????:
    <INPUT type=file id=File1 name=File1 runat="server" />
    <br>
    <input type="submit" id="Submit1" value="Upload" runat="server" />
    					
  6. ?????? ???? ?? HTML<form>??? ?? ??? ??? ????? ???? ??:
    <form id="Form1" method="post" enctype="multipart/form-data" runat="server">
    <INPUT type=file id=File1 name=File1 runat="server" />
    <br>
    <input type="submit" id="Submit1" value="Upload" runat="server" />
    </form>
    					

WebForm1.aspx.cs ??? behind ???? ????? ??? ??????

WebForm1.aspx.cs ??? behind ????? ??????? ???? ????? ??? uploaded ???? ??????? ???? ??, ????? ????? ?? ???? ????:
  1. ????? ????????????? ??,??????.
  2. ???-????? ?????????. ????? Studio WebForm1.aspx.cs ??? behind ????? ?? ????? ?? ?? ????? ???? ??? ?? ???? ?? ????? ??:
    private void Submit1_ServerClick(object sender, System.EventArgs e)
    {
    
    
    }
  3. ???????? ???? ?? ????? ??? WebForm1.cs ????? ?? ???? ?? ???? ?? ????? ??:
    protected System.Web.UI.HtmlControls.HtmlInputFile File1;
    protected System.Web.UI.HtmlControls.HtmlInputButton Submit1;
    						
    ??? ?? ??? ????? ??? ????? ???? ??, ?????? ??? ????? ??? ????? ?????? ?? ???:
    public class WebForm1 : System.Web.UI.Page
    {
    					
  4. ????? ??? ?? ?????? ?????:
    private void Submit1_ServerClick(object sender, System.EventArgs e)
    {
    					
  5. ??? ????? ?????? ??????, ?? ???? ??? ????? ??? ?? ?????? ?? ??? ENTER ?????:
    if( ( File1.PostedFile != null ) && ( File1.PostedFile.ContentLength > 0 ) )
    {
    	string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
    	string SaveLocation = Server.MapPath("Data") + "\\" +  fn;
    	try
    	{
    		File1.PostedFile.SaveAs(SaveLocation);
    		Response.Write("The file has been uploaded.");
    	}
    	catch ( Exception ex )
    	{
    		Response.Write("Error: " + ex.Message);
    		//Note: Exception.Message returns a detailed message that describes the current exception. 
    		//For security reasons, we do not recommend that you return Exception.Message to end users in 
    		//production environments. It would be better to put a generic error message. 
    	}
    }
    else
    {
    	Response.Write("Please select a file to upload.");
    }
    ?? ??? ?? ?? ????? ????? ?? ???? ??? ?? ???? ??????? ???? ??? ??? ????? ????? ???? ??? ??, ?? ???? "????? ???? ????? ?? ??? ???? ????? ???? ?? ???" ????? ??????? ???? ??? ??? ??? ????? ???? ????? ??, ???? ????? ??? ?? ????? ?? ?????? ??System.IO??? ?????, ?? ???? ?????? ??? assembled ?? ??SaveAs??? ????? ?????? ???? ???? ??, ?? ??? ?? ????? ?? ???? ????? ?? ??File1.PostedFile.SaveAs?????? ??? ??? ????? trapped ??, ?? ????? ????? ?? ??????? ?? ????????? ???? ???? ???
  6. ?????? ???? ??Submit1??????? ??????????? ??:
    private void Submit1_ServerClick(object sender, System.EventArgs e)
    {
    	if( ( File1.PostedFile != null ) && ( File1.PostedFile.ContentLength > 0 ) )
    	{
    		string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
    		string SaveLocation = Server.MapPath("Data") + "\\" +  fn;
    		try
    		{
    			File1.PostedFile.SaveAs(SaveLocation);
    			Response.Write("The file has been uploaded.");
    		}
    		catch ( Exception ex )
    		{
    			Response.Write("Error: " + ex.Message);
    			//Note: Exception.Message returns detailed message that describes the current exception. 
    			//For security reasons, we do not recommend you return Exception.Message to end users in 
    			//production environments. It would be better just to put a generic error message. 
    		}
    	}
    	else
    	{
    		Response.Write("Please select a file to upload.");
    	}
    }

????????? ?? ??????? ????

???? Visual Studio .NET ?? ?????? ????? ?? ??? ?? ????????? ?? ??????? ???? ?? ???, ????? ????? ?? ???? ????:
  1. ????? ????????????? ??,?????? ?????.
  2. ?????? Explorer ???, ???? ?????WebForm1.aspx?? ????-????? ????, ?? ???? ?????????? ??? ?????.
  3. ??????? ??? WebForm1.aspx ????? ??, ?? ??? ????? ???????????.
  4. ?????????? ?????????? ????? ???, 4 ???????? (MB) ?? ???? ?? ?? ???? ????? ?? ??? ????, ?? ???? ??? ????? ?????????.
  5. ???? ?? ????? ???? ?? ??? ????? ?????????. ????? ??? ?? ??? ????? ?? ??? ????? uploads ?? "???? ????? ?? ???? ???" ????? ??????? ?????
  6. Windows Explorer ?? ???? ?????? ?? ??? ???? ?????, ?? ?? ???? ?????????? ?? ?????? ??????
  7. ???????? ???? ?? ????? ???? ?? ????? ?? ???? ??? ?? ???????????

???? ??????? ????? ????

?????? ???????? ??? ??, ASP.NET ???? ???? ??????? ?? 4,096 ???????? (KB) (?? 4 MB) ?? ???? ?? ??? ????? ?? ????? ???? ?? ???? ???? ??????? ?? ????? ???? ?? ??? ?? ????????? ???? ????maxRequestLength?? ????????<httpruntime></httpruntime>?????? ??? Web.config ????? ???

???:??maxRequestLengthMachine.config ????? ??? ??????? ??? ??, ?? ???? ??? ?? ?????? ????? ?? (?????? ?? ???, ?? ????? ?????) ?? ?? ??? ?? ???? ??maxRequestLength, ??? ????? ?????? ????? ????????? ???? ???? ?? ????? ???? ????, Microsoft Internet Explorer "???? ???? ????? ?? DNS" ?????? ????? ????????? ?????

??? ?? ??? ???????? ?? ? ???? ?? asp.NET ????????? ?? ??? ?? ?????? ?? ????????? ???? ????? ???, ?? ?? Machine.config ??????? ???? ?????? ??????

???????? ??? ??,<httpruntime></httpruntime>???? Machine.config ??? ????? ???????? ?? ??? ??? ?? ?????:
<httpRuntime 
executionTimeout="90" 
maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false" 
minFreeThreads="8" 
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
/>
				
Machine.config ????? ??? ????? ?? \?????? ???\Microsoft.NET\Framework\??????? ???????\CONFIG ???????????


??? ??????? ?????

WebForm1.aspx

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="CSharpUpload.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
    <title>WebForm1</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
  </HEAD>
  <body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" enctype="multipart/form-data" runat="server">
<INPUT type=file id=File1 name=File1 runat="server" >
<br>
<input type="submit" id="Submit1" value="Upload" runat="server" NAME="Submit1">
</form>

	
  </body>
</HTML>
				

WebForm1.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CSharpUpload
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.HtmlControls.HtmlInputFile File1;
		protected System.Web.UI.HtmlControls.HtmlInputButton Submit1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			// 
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			// 
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Submit1.ServerClick += new System.EventHandler(this.Submit1_ServerClick);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Submit1_ServerClick(object sender, System.EventArgs e)
		{
			if( ( File1.PostedFile != null ) && ( File1.PostedFile.ContentLength > 0 ) )
			{
				string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
				string SaveLocation = Server.MapPath("Data") + "\\" +  fn;
				try
				{
					File1.PostedFile.SaveAs(SaveLocation);
					Response.Write("The file has been uploaded.");
				}
				catch ( Exception ex )
				{
					Response.Write("Error: " + ex.Message);
					//Note: Exception.Message returns a detailed message that describes the current exception. 
					//For security reasons, we do not recommend that you return Exception.Message to end users in 
					//production environments. It would be better to return a generic error message. 
				}
			}
			else
			{
				Response.Write("Please select a file to upload.");
			}
		}
	}
}
	

???? ???????

Theoretically, ?????? ????? ????? ???? fairly ???? ??? ???????, ASP.NET ????????? ?????????, ?? ???? ?? ???? ????? asp.NET ??? ???? ???? ???????? ASP.NET ????? ????????? ??? ??? ??????? ??? ????? 2 ???????? (GB) ?? ??? ???????, ASP.NET ????? ????????? ???? ????? 1 GB little ?? ?? ???? ????????? ??????? ?? ?????? ????????????? ?? ?????

During the upload process, ASP.NET loads the whole file in memory before the user can save the file to the disk. Therefore, the process may recycle because of thememoryLimit?? ???????processModeltag in the Machine.config file. ThememoryLimitattribute specifies the percentage of physical memory that the ASP.NET worker process can exhaust before the process is automatically recycled. Recycling prevents memory leaks from causing ASP.NET to crash or to stop responding.

Additionally, other factors play a role in the maximum file size that can be uploaded. ?? ???? ?????? ??????, ????? ????? ?????, ???????? ???, ?? ??????? ??????? ???????? ????? ??? ????? ?? ?? ??? ??????? ?? ?????? ??????? ?? ??? Microsoft ??????? ???? ?? 20 ???? ?? ??? 10 ?????????? (MB) ?? ?????? ??? ?????? ????? ???? ?? ?????? ??? ?? ???? ?? ??????? ?????, ?????? ????? ???? 100 MB ?? ???? ???

???:?? asp.NET ??? 100 MB ?? ???? ??????? ?? ????? ?? ???? ???? ???????, Microsoft ??????? ???? ?? ?? ?? ???? ??? ???????? ?????? ????? ????? ???? ?? ???? ????? ???? precise ????? ???? ?????????, ???? stress ?? ??????? ??? ????? ???? ????? ?? ???? ???? ?????????? ?? ??????? ?? ??? ???

??? ?? ???? ????? ????????? ?? ????? ????? ???? ?????? ??? ??, ?? ???? ????? ?????? ????? ????? ?? ???? ??:
  • ????? ????????? ???? ?? ????.
  • ????? ????????? ?? ?????? ???? ??
    ????? ??? ??? ?????? ????? ????? ?? ???? ????:

    aspnet_wp.exe (PID:PIDNumber) ?????? ?? ????? ?? ???? ?? ?? ?? ??????? ????????? ??SizeLimit?? (????????? ??????? ?????? RAM)?

  • ?? ?????? ?? ????? System.OutOfMemoryException thrown ???? ??? ???
?? ?? uploads ?? ???? ???? ???? ?? ?? ??? ???? ??? ??? ?? Windows ????? ??????? ??? Aspnet_wp.exe ????????? ?????, ?? ?? ?? ?????? ?????? ????? 64 KB ?? ???????? 2 ??? 1 ????? ????? ???? ????? ?? ???? ?? ???? ?? ?? ???? responseDeadlock ?????? ?? ???? ??????? ???? ?? ??? asp.NET ????? ????????? ?? ???? ?? ???? ???

??????

???????? ??????? ?? ???, ????? Microsoft ?????? ??????? (MSDN) ??? ??????; ?? ????.
<httpruntime>????</httpruntime>
(vs.71) http://msdn2.Microsoft.com/en-us/library/e1f13641 .aspx

????? ???? | ????? ????????
(VS.85) http://MSDN.Microsoft.com/en-us/library/ms535260 .aspx

ENCTYPE ??????? | enctype ???
HTTP://msdn2.Microsoft.com/en-us/library/ms533745.aspx

HtmlInputFile ????
(vs.71) http://msdn2.Microsoft.com/en-us/library/SYSTEM.Web.UI.htmlcontrols.htmlinputfile .aspx

HtmlInputFile.PostedFile ???
(vs.71) http://msdn2.Microsoft.com/en-us/library/SYSTEM.Web.UI.htmlcontrols.htmlinputfile.postedfile .aspx

???

???? ID: 323246 - ????? ???????: 04 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
  • Microsoft ASP.NET 1.0
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft ASP.NET 1.1
  • Microsoft Visual C# .NET 2003 Standard Edition
??????: 
kbhowtomaster kbmt KB323246 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:323246

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com