文件下载报错:引发类型为“System.OutOfMemoryException”的异常-.Net 内存溢出
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[]);
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[], System.Text.Encoding.UTF8));
//不指明Content-Length用Flush的话不会显示下载进度
HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
HttpContext.Current.Response.TransmitFile(filePath, , 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 内存溢出的更多相关文章
- 引发类型为“System.OutOfMemoryException”的异常
在运维工作中,经常能接到客户的反馈这个:引发类型为“System.OutOfMemoryException”的异常.客户反馈物理内存都还有富余,怎么报内存不足的错误呢! 什么时候会引发System.O ...
- sqlserver,执行生成脚本时“引发类型为“System.OutOfMemoryException”的异常”(已解决)
sqlserver,执行生成脚本时“引发类型为“System.OutOfMemoryException”的异常”(已解决) 出现此错误主要是因为.sql的脚本文件过大(一般都超过100M)造成内存无法 ...
- asp.net 引发类型为“System.OutOfMemoryException”的异常
asp.net 引发类型为“System.OutOfMemoryException”的异常通常发生在IIS进程获取不到内存时. 临时解决方法是: 回收IIS的应用程序池. 如果要比较好的解决办法是: ...
- nopCommerce 安装失败: 引发类型为“System.OutOfMemoryException”的异常。
如果你在安装nopCommerce 3.00版本的时候报如上异常,解决方案: 1.在服务器上检查内存是否已经满了,因为nopCommerce 在安装的时候需要很多内存. 2.关闭占用内存大的进程,保证 ...
- SharePoint 2013 引发类型为“System.ArgumentException”的异常。 參数名: encodedValue
SharePoint 2013 引发类型为"System.ArgumentException"的异常. 參数名: encodedValue 具体错误信息 说明: 运行当前 Web ...
- sharepoint 配置失败,已引发类型为System.ArgumentException的异常。其他异常信息:domainName参数不支持指定的值。
解决方法:在域控制器中加入sharepoint计算机,设置为administrators组中
- eclipse+Maven插件报错:-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
问题描述: eclipse indigo+maven3.3.3+jdk1.70 maven插件执行报错:-Dmaven.multiModuleProjectDirectory system prope ...
- ATOM系列之-atom报错"Cannot load the system dictionary for zh-CN"
atom报错"Cannot load the system dictionary for zh-CN" 想必很多人(程序猿&程序媛)都和我一样,喜欢的这款很拉风的代码编辑器 ...
- Atom | 报错 Cannot load the system dictionary for zh-CN的解决办法
文章目录 问题描述 推荐阅读 查找问题所在 解决方案 (二选一) 问题描述 最近这款优秀的编辑器 atom,报错 Cannot load the system dictionary for zh-CN ...
随机推荐
- MySql之视图的使用
一:视图是什么 视图相当于一个窗口,一个基于具体数据库表.定义了相关查询规则 的窗口. 建立视图,可以重用一些复杂的查询语句. 建立视图,相当于定义了一系列查询操作:从视图查询数据,相当于在调用 ...
- 鼠标滑过table时修改表格行的背景颜色
方法一: #customers tr:hover { background-color: #f00; } 方法二: <tr onmouseover="style.backgroundC ...
- hdoj 2594 Simpsons’ Hidden Talents 【KMP】【求串的最长公共前缀后缀】
Simpsons' Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- 让人非常easy误解的TCP拥塞控制算法
正文 非常多人会觉得一个好的TCP拥塞控制算法会让连接加速,这样的观点是错误的.恰恰相反,全部的拥塞控制算法都是为了TCP能够在贪婪的时候悬崖勒马,大多数时候.拥塞控制是减少了数据发送的速度. 我在本 ...
- cocos2d-x与UIKit混合编程实现半透明效果
关键词 cocos2d-x, UIKit, transparent 问题 cocos2d-x使用一个专门的OpenGL View进行渲染, 它的渲染和UIKit是分开进行的, 因此我们使用时一般是把c ...
- TypeError: sequence item 0: expected string, Tag found
原始代码: soup = BeautifulSoup(result, 'html.parser') content_list = soup.find_all('p', attrs={"cla ...
- CentOS 7 配置HTTPS加密访问SVN
上一篇文章已经介绍了如何在CentOS7环境下安装SVN并整合HTTP访问 http://www.cnblogs.com/fjping0606/p/7581093.html 那么本文则介绍如何添加HT ...
- [svc]数字证书基础知识
数字证书基础原理 数字证书采用PKI(Public Key Infrastructure)公开密钥基础架构技术,利用一对互相匹配的密钥进行加密和解密. 每个用户自己设定一把特定的仅为本人所知的私有密钥 ...
- java 生成Http 头部date格式的string-RFC 1123 Date Representation in java
https://blog.csdn.net/lvzhuyiyi/article/details/51770148 ******************************************* ...
- Geany的"跳转到标记定义“功能如何使用
Geany是个比较轻量级的代码编辑器,在一些不怎么需要编辑的代码上,我比较常用它来浏览代码.不过它的 跳转到标记定义(Go to tag definition) 功能有点奇怪,一开始死活不知道怎么用, ...