读书人

这个页面执行完毕后IE自动关闭是如何实

发布时间: 2012-01-15 22:57:49 作者: rapoo

这个页面执行完毕后IE自动关闭是怎么实现的。
功能是每隔一段时间(通过任务计划实现)服务器自动打开这个页面,然后自动备份数据并打压缩包,再自动传送到ftp服务器上去。
目前我不能执行这个页面,但是他可以完成后自动关闭,我看了代码,不知道为什么会自动把IE关闭掉。
后台代码:(前台没任何特殊性)

C# code
using System;using System.IO;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Diagnostics;using System.Net;public partial class BackupDB_Default : System.Web.UI.Page{    #region Define Variables    bool isSuccess = false;    string ftpServerIP = "101.101.10.104";//Remote Server    int ftpPort = 21;    string ftpUserID = "T";    string ftpPassword = "abcdef11";    string pBackupDBAndCompressFilesPath = @"D:\DataCenter";    string pBackupDBFileName = "Iridian2#168EW@370$.bak";    string pCompressFileName = "Iridian2#168EW@370$.rar";    #endregion    #region Page_Load    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            if (Directory.Exists(pBackupDBAndCompressFilesPath))                BackupDatabase();        }    }    #endregion    #region BackupDatabase    private void BackupDatabase()    {        //SQLDMO.dll is a COM Object ,Microsoft SQl Server provider        SQLDMO.Backup pBackup = new SQLDMO.BackupClass();        SQLDMO.SQLServer pSqlServer = new SQLDMO.SQLServerClass();        try        {            pSqlServer.LoginSecure = false;            pSqlServer.Connect("110.110.10.5", "sa", "1111");//Server IP,Database Login UserName and Password            pBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;            pBackup.Database = "Iridian2";            pBackup.Files = pBackupDBAndCompressFilesPath + "\\" + pBackupDBFileName;            pBackup.BackupSetName = "Iridian2";            pBackup.BackupSetDescription = "Database Backup";            pBackup.Initialize = true;            pBackup.SQLBackup(pSqlServer);            isSuccess = true;        }        catch (Exception ex)        {            isSuccess = false;            Response.Write(ex.Message);        }        finally        {            pSqlServer.DisConnect();            if (isSuccess)            {                bool isCompressSuccess = false;                if (File.Exists(pBackupDBAndCompressFilesPath + "\\" + pBackupDBFileName))                    isCompressSuccess = CompressDBBackupFile(pBackupDBAndCompressFilesPath + "\\" + pBackupDBFileName, pBackupDBAndCompressFilesPath, pCompressFileName);                if (isCompressSuccess)                SendZipFileToAnotherComputer(pCompressFileName);            }        }    }    #endregion    #region CompressDBBackupFile    private bool CompressDBBackupFile(string patch, string rarPatch, string rarName)    {        bool excuteSuccess = false;        String the_Info;        ProcessStartInfo the_StartInfo;        Process the_Process = new Process();        try        {            the_Info = " a    " + rarName + "  " + patch + "  -r  -o+  -m5  -pEW#123@";//Set Password:EW#123@            the_StartInfo = new ProcessStartInfo();            the_StartInfo.FileName = @"C:\Program Files\WinRAR\WinRAR.exe";//Winrar install path            the_StartInfo.Arguments = the_Info;            the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;            the_StartInfo.WorkingDirectory = rarPatch;            the_Process.StartInfo = the_StartInfo;            the_Process.Start();            excuteSuccess = true;        }        catch (Exception ex)        {            excuteSuccess = false;            Response.Write(ex.Message);        }        finally        {            the_Process.WaitForExit();            if (the_Process != null)            {                the_Process.Close();                the_Process = null;            }        }        return excuteSuccess;    }    #endregion    #region SendZipFileToAnotherComputer    private void SendZipFileToAnotherComputer(string filename)    {        FileInfo fileInf = new FileInfo(pBackupDBAndCompressFilesPath + "\\" + filename);        string uri = "ftp://" + ftpServerIP + ":" + ftpPort.ToString() + "/" + fileInf.Name;//FTP Format:ftp://user:password@ftpserver:port/url-path        FtpWebRequest reqFTP;        reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));        reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);        reqFTP.KeepAlive = false;        reqFTP.Method = WebRequestMethods.Ftp.UploadFile;        reqFTP.UseBinary = true;        reqFTP.ContentLength = fileInf.Length;        int contentLen;        int buffLength = 2048;//The buffer size is set to 2kb        byte[] buff = new byte[buffLength];        FileStream fs = null;        Stream strm = null;        try        {            fs = fileInf.OpenRead();            strm = reqFTP.GetRequestStream();            contentLen = fs.Read(buff, 0, buffLength);            while (contentLen != 0)            {                strm.Write(buff, 0, contentLen);                contentLen = fs.Read(buff, 0, buffLength);            }        }        catch (Exception ex)        {            Response.Write("Upload Error:" + ex.Message);        }        finally        {            if (strm != null)            {                strm.Close();                strm = null;            }            if (fs != null)            {                fs.Close();                fs = null;            }            reqFTP.Abort();        }    }    #endregion} 



前台

HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="BackupDB_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title>Backup Database</title></head><body>    <form id="form1" runat="server">    <div>        </div>    </form></body></html>


[解决办法]
呀··
顶下先···
倒分给我吧·····
[解决办法]
是关闭还是崩溃,先确定一下先吧。
[解决办法]
从代码上确实没看出来 不如上传一个小的文件跟踪下 或许能发现其中奥妙
不过你用js也能关掉啊
[解决办法]
为何不用WinForm做呢,反正都是用任务计划调用
WinForm多简单,自动关闭直接在Form_Load事件里调用Close()方法就OK了
[解决办法]
或者是在FtpWebRequest这个类里面有的方法也说不一定,现在公布的代码里面没有哪句是关闭IE的

读书人网 >asp.net

热点推荐