Asp.net 中导出excel后终止进程的解决办法
在asp.net里使用com组件导出excel后总是会有一个EXCEL.EXE进程存在,占据着30多M的内存,研究了好久试了网上的很多办法都没有解决。今天心情比较放松,接着从网上搜了一下,看到一篇帖子如下:
在DOT NET中调用Excel后,Excel进程的并未终止问题的解决办法 收藏
在DOT NET中调用Excel后,Excel进程的并未终止问题
Excel.Application myExcel = new Excel.Application() ;
...
myExcel.Quit();
网上的解决办法大多是说在myExcel.Quit()后强制进行垃圾回收
GC.Collect();
但是都不行,还有人说要释放对该Com对象(myExcel)的引用
for(int i =1;i>0;i= System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel))
{
}
还有人说把myExcel 创建为局部变量,方法结束后垃圾回收器会清理它,好像也不行(即使在这个方法最后强制垃圾回收器收集垃圾也不行)。
垃圾回收器似乎没有工作,似乎和垃圾回收的策略有关,微软的这个Dot Net清洁工不清理自己所在地的垃圾! GC.Collect()不清理自己所在作用域的垃圾,在调用Excel的方法之外调用GC.Collect() 就好了,进程列表中Excel的进程在GC.Collect() 后就消失了。
void DoSomething()
{
...
HandleExcel();
GC.Collect() ;
}
void HandleExcel()
{
Excel.Application myExcel = new Excel.Application() ;
...
myExcel.Quit();
}
这个方法在winform程序中有效,但是对于在asp.net中还是不行(好像是微软的问题)。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/sunyou/archive/2005/08/22/461133.aspx
按照所说的方法试试:
首先实验:
protected void Export_Click(object sender, EventArgs e)
{
Excel.Application myExcel = new Excel.Application() ;
...
myExcel.Quit();
GCCollect();
}
public void GCCollect()
{
GC.Collect();
}
这样做导出excel后进程还存在。
接着试
protected void Export_Click(object sender, EventArgs e)
{
ExportExcel();
相关文档:
Asp.Net Forms验证(自定义、角色提供程序、单点登录)
以前开发项目时经常是自己开发一套用户权限管理系统进行验证,比较灵活。最近为了单点登录的问题又把Asp.Net自带的验证方式看了一遍,发现这种方式也比较方便,功能也还可以。在Asp.Net提供了三种常用的验证方式:Windows方式是和IIS结合起来可以实现基本、摘要、集成 ......
1. 打开新的窗口并传送参数:
传送参数:
response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')</script>")
接收参数:
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
2.为按钮添加对话框
Button1.Att ......
一、ASP.NET Web Service代码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.SqlClient;
namespace WebService1
{
/// <sum ......
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;//Cryptography密码术
namespace DAL
{
public class Enc ......
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace class_new
{
/// <summary>
/// DataClass 的摘要说明。
/// </summary>
public class DataClass
{
private string strConnection="";
&n ......