文件下载报错:引发类型为“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 ...
随机推荐
- postgresql ltree类型
最近一个月使用Postgresql的时候,经常遇到ltree的数据,感觉有些别扭,可是有绕不过去.今天决心整理一下,以后使用方便一些. 一.简介 ltree是Postgresql的一个扩展类型,由两位 ...
- 【Zookeeper】源码分析之网络通信(三)之NettyServerCnxn
一.前言 前面已经学习了NIOServerCnxn,接着继续学习NettyServerCnxn. 二.NettyServerCnxn源码分析 2.1 类的继承关系 public class Netty ...
- tar 的–exclude参数,实现不包括某些文件(转)
最近有人问我tar压缩能不能不包含不想要的文件或者文件夹 压缩包很利于传送,备份等等.但比如大量的日志文件一般是不需要备份,或者需要分开备份. tar参数中的–exclude,这个是我在看鸟哥私房菜时 ...
- fiddler展示serverIP方法
转载自:http://www.xuanfengge.com/fiddler-displays-the-set-ip-method.html 前言 由于web前端在多个环境中开发,需要经常更换host, ...
- linux达人养成计划学习笔记(八)—— shell基础
一.shell概念 shell是一个命令行解释器,它为用户提供了一个向linux内核发送请求以便运行程序的界面系统级程序,用户可以用shell来启动.挂起.停止甚至编写一些程序. shell还是一个功 ...
- 将csv的数据导入mysql
手头有一份8MB的CSV文件需要分析,对于程序员来说,还有比在数据库里分析更愉快的事情吗? 所以让我们把CSV导入MYSQL吧. 一.首先按照文件列数创建相应的SQL表 例如: DROP TABLE ...
- Fiddler插件开发 - 实现网站离线浏览功能
有这么一种应用场景: 你是做前端或APP开发的,需要调用服务端提供的接口,接口只能在公司内网访问:在公司外就无法调试代码了. 想在公司外访问怎么办呢? 如果在公司的时候将所有接口的响应内容都保存起来, ...
- .NET Memory Allocation Profiling with Visual Studio 2012
.NET Memory Allocation Profiling with Visual Studio 2012 This post was written by Stephen Toub, a fr ...
- Go 实现异常处理机制
实例: package main import "fmt" type DevideError struct { devidee int devider int } func (de ...
- Java8学习笔记(七)--Collectors
本系列文章翻译自@shekhargulati的java8-the-missing-tutorial 你已经学习了Stream API能够让你以声明式的方式帮助你处理集合.我们看到collect是一个将 ...