標籤:exce 應用程式 protected ext 運行 final 清理 star local
CSDN:http://blog.csdn.net/huwei2003/article/details/53559272
設定了也沒有用,於是想到手動清理應用程式集區,但又遷配置問題於是改成最後的方式!
protected void StartStopRecycleApp(string method) { string AppPoolName = this.tbAppName.Text.Trim(); //string method = "Recycle"; try { DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools"); DirectoryEntry findPool = appPool.Children.Find(AppPoolName, "IIsApplicationPool"); findPool.Invoke(method, null); appPool.CommitChanges(); appPool.Close(); lbMsg.Text = string.Format("應用程式集區{0}{1}成功", AppPoolName,method); } catch (Exception ex) { lbMsg.Text = string.Format("應用程式集區{0}{2}失敗:{1}", AppPoolName, ex.Message,method); } }
tbAppName是一個textbox,用來輸入應用程式集區的名字,如“DefaultAppPool”。
當method="Recycle"時就是回收,為“Start”時是啟動,為“Stop”時是停止。
注意:
1. 必須引入System.DirectoryServices包
2. 運行此程式的應用程式也的使用者必須許可權比較高,可以單獨為此程式提供應用程式程,或者建立一個虛擬目錄在配製裡類比進階使用者(如administrators或者system),否則應用程式會拋出“拒絕訪問”的異常。
var filePath=Server.MapPath("~/_UploadFile/" + paths[0]); if (File.Exists(filePath)) { try { FileInfo info = new FileInfo(filePath); long fileSize = info.Length; HttpContext.Current.Response.Clear(); //指定Http Mime格式為壓縮包 HttpContext.Current.Response.ContentType = "application/x-zip-compressed"; // Http 協議中有專門的指令來告知瀏覽器, 本次響應的是一個需要下載的檔案. 格式如下: // Content-Disposition: attachment;filename=filename.txt HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(paths[1], System.Text.Encoding.UTF8)); //不指明Content-Length用Flush的話不會顯示下載進度 HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString()); HttpContext.Current.Response.TransmitFile(filePath, 0, fileSize); HttpContext.Current.Response.Flush(); } catch { } finally { HttpContext.Current.Response.Close(); } //byte[] buffer = null; //using (FileStream stream = new FileStream(Server.MapPath("~/_UploadFile/" + paths[0]), FileMode.Open, FileAccess.Read)) //{ // if (stream.Length > 1000000) { // StartStopRecycleApp("Recycle"); // } // buffer = new byte[stream.Length]; // stream.Read(buffer, 0, buffer.Length); // stream.Close(); //} //if (buffer != null) //{ // Response.Clear(); // Response.Charset = "gb2312"; // Response.ContentType = "application/octet-stream"; // Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(paths[1], System.Text.Encoding.UTF8)); // Response.AddHeader("Content-Length", file.fileSize.ToString()); // Response.BinaryWrite(buffer); // Response.Flush(); // Response.End(); //} }
檔案下載報錯:引發類型為“System.OutOfMemoryException”的異常-.Net 記憶體溢出