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. maven超级pom内容

    1.位置 2.内容 <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the A ...

  2. CSS 居中布局

    来源:http://www.cnblogs.com/QianBoy/p/8539077.html 水平居中 1)使用inline-block+text-align 原理:先将子框由块级元素改变为行内块 ...

  3. 基于Ubuntu部署 memcached 服务

    系统要求:Ubuntu 16.04.1 LTS 64 位操作系统 安装并启动 memcached 服务 安装 memcached 使用apt-get安装 memcached sudo apt-get ...

  4. Effective Java 第三版——50. 必要时进行防御性拷贝

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  5. Atitit 开发进度 开发效率提升解决方案

    Atitit 开发进度  开发效率提升解决方案 1.1. 使用4gl语言 dsl语言尽可能 1 1.2. Ssd+高屏幕显示器,提升硬件 1 1.3. 汉字命名规范,可以大力提升可读性与效率 1 1. ...

  6. 浅谈 OpenResty

    一.前言 我们都知道Nginx有很多的特性和好处,但是在Nginx上开发成了一个难题,Nginx模块需要用C开发,而且必须符合一系列复杂的规则,最重要的用C开发模块必须要熟悉Nginx的源代码,使得开 ...

  7. [转]新人常识普及:我们为什么必须会git和maven

    转自贴吧:http://tieba.baidu.com/p/3458400116 鉴于本吧多新人,新人又需要多交流才能进步,今天就给新人们讲讲git和maven的必要性,因为,他们的重要性,远远超过很 ...

  8. 模仿CountDownLatch类自定义倒时计时器

    简介 这里模仿CountDownLatch类自定义到时计时器,利用AQS模板中的尝试获得共享和释放共享 1.MyCountDownLatch package com.jacky; import com ...

  9. Swagger使用小记

    Swagger是一种框架,用于自动生成Restfull API的文档,而不用开发者自己编写文档.它既可以减少我们创建文档的工作量,同时说明内容又整合入实现代码中,让维护文档和修改代码整合为一体,可以让 ...

  10. hello alibaba

    http://ifeve.com/dubbo-learn-book/ http://ifeve.com/leader-follower-thread-model/ http://ifeve.com/a ...