分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

文件下载报错:引发类型为“System.OutOfMemoryException”的异常-.Net 内存溢出

发布时间:2023-09-06 01:06责任编辑:傅花花关键词:暂无标签

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 内存溢出

原文地址:http://www.cnblogs.com/xiaoruilin/p/7424318.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved