ASP.NETÎļþÏÂÔØº¯ÊýʹÓÃdzÎö
ASP.NETÎļþÏÂÔØº¯ÊýʹÓÃÊÇʲôÇé¿öÄØ£¿ÔÚÄãµÄPage_LoadÖÐÌí¼ÓÕâÑùµÄ´úÂë:
Page.Response.Clear();
bool success = ResponseFile(Page.Request, Page.Response, "Ä¿µÄÎļþÃû³Æ", @"Ô´Îļþ·¾¶", 1024000);
if (!success) Response.Write("ÏÂÔØÎļþ³ö´í£¡"); Page.Response.End();
ASP.NETÎļþÏÂÔØº¯Êý´úÂëΪ:
public static bool ResponseFile(HttpRequest _Request,HttpResponse _Response,string _fileName,string _fullPath, long _speed) {
try
{
FileStream myFile = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
BinaryReader br = new BinaryReader(myFile);
try
{
_Response.AddHeader("Accept-Ranges", "bytes"
);
_Response.Buffer = false;
long fileLength = myFile.Length;
long startBytes = 0; double pack = 10240;
//10K bytes
//int sleep = 200;
//ÿÃë5´Î ¼´5*10K bytesÿÃë int sleep = (int)Math.Floor(1000 * pack / _speed) + 1;
if (_Request.Headers["Range"] != null)
{
_Response.StatusCode = 206;
string[] range = _Request.Headers["Range"].Split(new char[] {'=', '-'});
startBytes = Convert.ToInt64(range[1]);
}
_Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
if (startBytes != 0) {
//Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength-1, fileLength));
}
_Response.AddHeader("Connection", "Keep-Alive");
_Response.ContentType = "application/octet-stream";
_Response.AddHeader("Content-Disposition","attachment; filename=" + HttpUtility.UrlEncode(_fileName,System.Text.Encoding.UTF8) ); br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
int maxCount = (int) Math.Floor((fileLength - startBytes) / pack) + 1;
for (int i = 0; i < maxCount; i++) { if (_Response.IsClientConnected) { _Response.BinaryWrite(br.ReadBytes(int.Parse(pack.ToString()))); Thread.Sleep(sleep);
} else { i=maxCount;
}
} }
catch
{
return false;
}
finally
{
br.Close();
myFile.Close();
}
}
catch
{
return false;
}
return true;
}
ÕâÑù¾ÍʵÏÖÁËÎļþÏÂ
Ïà¹ØÎĵµ£º
ÔÚ½« ASP.NET Web ²¿¼þµÄ¼¯³É¿Ø¼þ¼¯ÖеĿؼþ°üÀ¨ÔÚÍøÒ³ÖÐʱ£¬ÕâЩ¿Ø¼þ½«×ñÊØ¸ÃÒ³µÄ¹æÔò£»¾ßÌå¶øÑÔ¾ÍÊÇ£¬ÕâЩ¿Ø¼þ½«ÔÚ¸ÃÒ³µÄÉúÃüÖÜÆÚÄÚÔËÐС£
ÿ¸öÍøÒ³¶¼¾ßÓÐÒ»¸öÉúÃüÖÜÆÚ£¬ÍøÒ³ÔÚÆäÉúÃüÖÜÆÚÄÚ½«Ö´ÐÐһϵÁд¦Àí²½Öè¡£ÕâЩ²½Öè°üÀ¨³õʼ»¯¡¢´´½¨¿Ø¼þ¡¢»¹ÔºÍά»¤×´Ì¬¡¢ÔËÐÐʼþ´¦Àí³ÌÐò´ú ......
BehaviorEditorPart Web ·þÎñÆ÷¿Ø¼þÊÇÒ»¸ö±à¼Æ÷²¿¼þ¿Ø¼þ£¬×îÖÕÓû§¿ÉÒÔʹÓøÿؼþÔÚÔËÐÐʱ¸ü¸Ä¹ØÁªµÄ WebPart ¿Ø¼þÉϵĶà¸öÓû§½çÃæ (UI) ÊôÐÔ¡£Ï±íÁгöÁËÓû§¿É×Ô¶¨ÒåµÄ¹¦ÄÜ£¬ÒÔ¼°Óû§¿ÉʹÓà BehaviorEditorPart ¿Ø¼þ±à¼µÄ¶ÔÓ¦µÄ WebPart ¿Ø¼þÊôÐÔÖµ¡£
Óû§¿É×Ô¶¨ÒåµÄ¹¦ÄÜ
WebPart ......
ASP.NETµÄ¹¤×÷ÔÀí
ÔÚ¶àÊý³¡ºÏÏ£¬¿ÉÒÔ½«ASP.NETÒ³Ãæ¼òµ¥µØ¿´³ÉÒ»°ãµÄHTMLÒ³Ãæ£¬Ò³Ãæ°üº¬±ê¼ÇÓÐÌØÊâ´¦Àí·½Ê½µÄһЩ´úÂë¶Î¡£µ±°²×°.NETʱ£¬±¾µØµÄIIS Web·þÎñÆ÷×Ô¶¯ÅäÖóɲéÕÒÀ©Õ¹ÃûΪ.aspxµÄÎļþ£¬ÇÒÓÃASP.NETÄ£¿é(ÃûΪaspnet_isapi.dllµÄÎļþ)´¦ÀíÕâЩÎļþ¡£
´Ó¼¼ÊõÉϽ²£¬ASP.NETÄ£¿é·ÖÎöASPXÎļþµÄÄÚÈÝ£¬²¢½«ÎļþÄÚÈ ......
Ïã¸ÛÄDZ߹«Ë¾µÄÊг¡²¿¿ª»áʱҪÇóÎÒÃÇÕâ±ßʵÏÖÒ»¸ö¶¨Ê±·¢ËÍÓʼþµÄ¹¦ÄÜ£¬¼´ÔÚÿÌìÏÂÎç5µã×óÓÒ¶¨Ê±°Ñ½ñÌìÒÑͨ¹ýÈýÉóµÄ¶©µ¥ÐÅÏ¢·¢¸øÊг¡²¿µÄ¾Àí£¬¸æËßËûÄÄЩ¶©µ¥ÒѾͨ¹ýÁËÖÕÉ󡣯½Ê±Ö»ÖªµÀÈçºÎÓÃ.net·¢ËÍÓʼþ£¬µ«²»ÖªÈçºÎ¶¨Ê±·¢ËÍÓʼþ¡£ÓÚÊǰٶÈÁËһϣ¬×ܽáÆðÀ´ÓÐÒÔÏÂÄÇôÈýÖÖ£º
£¨1£©×öÒ»¸öwinform À´¶¨Ê±·¢Óʼþ¡£È»ºóͨ¹ý ......