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 内存溢出的更多相关文章

  1. 引发类型为“System.OutOfMemoryException”的异常

    在运维工作中,经常能接到客户的反馈这个:引发类型为“System.OutOfMemoryException”的异常.客户反馈物理内存都还有富余,怎么报内存不足的错误呢! 什么时候会引发System.O ...

  2. sqlserver,执行生成脚本时“引发类型为“System.OutOfMemoryException”的异常”(已解决)

    sqlserver,执行生成脚本时“引发类型为“System.OutOfMemoryException”的异常”(已解决) 出现此错误主要是因为.sql的脚本文件过大(一般都超过100M)造成内存无法 ...

  3. asp.net 引发类型为“System.OutOfMemoryException”的异常

    asp.net 引发类型为“System.OutOfMemoryException”的异常通常发生在IIS进程获取不到内存时. 临时解决方法是: 回收IIS的应用程序池. 如果要比较好的解决办法是: ...

  4. nopCommerce 安装失败: 引发类型为“System.OutOfMemoryException”的异常。

    如果你在安装nopCommerce 3.00版本的时候报如上异常,解决方案: 1.在服务器上检查内存是否已经满了,因为nopCommerce 在安装的时候需要很多内存. 2.关闭占用内存大的进程,保证 ...

  5. SharePoint 2013 引发类型为“System.ArgumentException”的异常。 參数名: encodedValue

    SharePoint 2013 引发类型为"System.ArgumentException"的异常. 參数名: encodedValue 具体错误信息 说明: 运行当前 Web ...

  6. sharepoint 配置失败,已引发类型为System.ArgumentException的异常。其他异常信息:domainName参数不支持指定的值。

    解决方法:在域控制器中加入sharepoint计算机,设置为administrators组中

  7. 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 ...

  8. ATOM系列之-atom报错"Cannot load the system dictionary for zh-CN"

    atom报错"Cannot load the system dictionary for zh-CN" 想必很多人(程序猿&程序媛)都和我一样,喜欢的这款很拉风的代码编辑器 ...

  9. Atom | 报错 Cannot load the system dictionary for zh-CN的解决办法

    文章目录 问题描述 推荐阅读 查找问题所在 解决方案 (二选一) 问题描述 最近这款优秀的编辑器 atom,报错 Cannot load the system dictionary for zh-CN ...

随机推荐

  1. 内联汇编中的asm和__asm__

    基本的内联汇编代码: asm格式: asm("assembly code"):   使用替换的关键字: 如果必须的话,可以改变用于标识内联汇编代码段的关键字asm.ANSI C规范 ...

  2. Kafka的安装和设置

    Kafka是一种分布式发布订阅消息系统. Kafka有三种模式: (1)单节点单Broker,在一台机器上运行一个Kafka实例: (2)单节点多Broker,在一台机器上运行多个Kafka实例: ( ...

  3. PostgreSQL之时间戳自动更新

    操作系统 :CentOS7.3.1611_x64 PostgreSQL版本 :9.6 问题描述 PostgreSQL执行Insert语句时,自动填入时间的功能可以在创建表时实现,但更新表时时间戳不会自 ...

  4. POCO Log库

    http://pocoproject.org/index.html 有个想法,把这个所谓的跨平台log库阉割成只支持win的,然后使代码尽量简化,高效,以后有时间就开始研究,哈哈.

  5. 跟我学SharePoint2013视频培训课程——版本控制示例(15)

    课程简介 第15天,SharePoint 2013版本控制示例 视频 SharePoint 2013 交流群 41032413

  6. s:iterator 标签使用错误记录

    <s:iterator value="newMarriageMoveList" id='tpNewMarriage' status="number"> ...

  7. DIOCP-DIOCPv5的处理能力

    今天和BB讨论了下DiocpV5的单连接处理能力.一直没有做过这方面的测试,稍微试了一下. 把开始的时候客户端Sleep(10),为了测试处理能力,把Sleep(10)去掉了,20秒(实际应该算17秒 ...

  8. 什么是位、字节、字、KB、MB (转)

    回顾一下按位操作符和移位操作符的知识,顺便复习一下位相关的基础知识. 位:"位(bit)"是电子计算机中最小的数据单位.每一位的状态只能是0或1. 字节:8个二进制位构成1个&qu ...

  9. AD域部署使用bginfo软件

    实验网络拓扑图: 实验目标: bginfo收集信息服务器通过bginfo软件收集每个域客户端信息录入到SQL server 2008数据库 bginfo软件官网下载地址: https://docs.m ...

  10. 创建sequence和触发器出现权限不足

    解决方式: 已sysdba登陆后,进行授权 grant create any sequence to [用户]创建sequence权限不足解决方法 grant create trigger to [用 ...