asp.net webforms应用程序使IE崩溃

时间:2014-08-14 03:16:24

标签: c# asp.net internet-explorer

我在asp.net网络表单中有一个应用程序。它可以简单地加载excel文件,转换它并下载转换后的文件。

我可以在任何其他浏览器(firefox,chrome等)上正常工作,但是在IE(任何版本)上它都不起作用。

我在visual studio中调试过,没有出现错误。

我在附加组件/防火墙/防病毒软件上禁用。

同样在浏览器上(Inspect element-F12),它不显示任何错误。

我不使用表单,页面是一个简单的文件上传和一个重新加载页面的按钮,在页面加载后面的代码上检查是否有文件而不是进程,否则加载页面。

因此,当我加载文件并单击“提交”时,IE会继续思考和思考,随时随地都可以使用。

其他浏览器会立即处理。

IE上是否存在任何不处理它的配置或错误,可能导致其中断/冻结的原因?

提前致谢

更新

背后的代码

public partial class pgs_Import : System.Web.UI.Page
{
    GIFTS.BankAccount ourAccount = new GIFTS.BankAccount ("00", "0000", "00000", "00");
    ReportingDBDataContext db = new ReportingDBDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (FUExpenses.HasFile)
        {
            DataTable dt = ImportData.ReadData(FUExpenses.PostedFile, ImportSource.Creditors);
            ProcessExpenses(dt, RBLType.SelectedValue);
        }
    }

    protected void ProcessExpenses(DataTable dt, string type)
    {
        string otherRef = "";
        string filePrefix = "";
        switch (type.ToUpper())
        {
            case "STAFFREIMBURSE":
                otherRef = "ReimburseExp";
                filePrefix = "StaffExpenses";
                break;
            case "ABCRENT":
                otherRef = "Rent";
                filePrefix = "Rent_";
                break;
            case "OTHER":
                otherRef = TxtOtherRef.Text;
                filePrefix = TxtOtherRef.Text.Replace(" ","_") + "_";
                break;
        }
        DateTime dueDate;
        if (!DateTime.TryParse(TxtCalendar.Text, out dueDate))
        {
            if (CalExtender.SelectedDate.HasValue)
                dueDate = CalExtender.SelectedDate.Value;
            else
                dueDate = DateTime.Now;
        }

        if (dueDate.Date < DateTime.Now.Date)
            throw new Exception("Can't travel back in time.  Enter a date today or later.");

        //60 days is a limit enforced by BNZ
        if (dueDate.Date > DateTime.Now.AddDays(60).Date)
            throw new Exception("That's forward planning!  But can't be more than 60 days in future.");

        GIFTS.GIFTSCreditBatch batch = new GIFTS.GIFTSCreditBatch(ourAccount, dueDate, ChkBulk.Checked);
        List<string> problems = new List<string>();

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow row = dt.Rows[i];
            try
            {
                GIFTS.GIFTSCreditRecordTransaction trans = new GIFTS.GIFTSCreditRecordTransaction();
                GIFTS.BankAccount acct = new GIFTS.BankAccount(row["Bank Branch"].ToString() + row["Account"].ToString());
                trans.OtherPartyAccountNumber = acct;
                decimal amt = Convert.ToDecimal(row["InvoiceAmount"]);
                amt = amt * 100;
                trans.TransactionAmount = Convert.ToInt32(amt);
                trans.TransactionCode = GIFTS.TransactionCodes.StandardCredit;
                trans.OtherPartyName = row["VendorID"].ToString();
                trans.OtherPartyReference = otherRef;
                trans.OtherPartyCode = row["Department"].ToString();
                trans.OtherPartyParticulars = row["Description"].ToString();
                trans.OriginatorName = "Company Name";
                trans.OriginatorCode = row["VendorID"].ToString();
                trans.OriginatorReference = row["Department"].ToString();
                trans.OriginatorParticulars = row["Description"].ToString();

                batch.Transactions.Add(trans);
            }
            catch (Exception exc)
            {
                //Don't add as a problem if the line is blank
                if (String.IsNullOrWhiteSpace(row["Bank Branch"].ToString()) && String.IsNullOrWhiteSpace(row["Account"].ToString()))
                    continue;

                problems.Add(String.Format("Row {0}: {1}", i + 2, exc.Message));
            }
        }

        if (problems.Count > 0)
        {
            StringBuilder sb = new StringBuilder();
            foreach (String problem in problems)
            {
                sb.Append(problem);
                sb.Append("<br />");
            }
            LblProblems.Text = sb.ToString();
        }
        else
        {
            string fileName = String.Format("{0}{1}-{2}-{3}.afi", filePrefix, (dueDate.Year % 100), dueDate.Month, dueDate.Day);
            WriteOutput("text/plain", fileName, batch.ToCSV());
        }
    }

    protected void WriteOutput(string contentType, string fileName, string content)
    {
        Response.Clear();
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
        Response.Charset = "";
        Response.ContentType = contentType;
        Response.Write(content);
        Response.End();
    }
}

namespace GIFTS
{

    public enum TransactionCodes
    {
        StandardCredit = 50,
        Payroll = 52,
        Dividends = 61,
        UNDEFINED = -1
    }

    public static class HelperMethods
    {

        public static bool IsValidFileCreationDate(DateTime date)
        {
            if (date < DateTime.Now)
                return false;
            else
                return true;
        }

        public static bool IsValidFileDueDate(DateTime date)
        {
            if (date < DateTime.Now.AddDays(-1) || date > DateTime.Now.AddDays(60))
                return false;
            else
                return true;
        }
    }

    /// <summary>
    /// For storing and formatting account numbers
    /// </summary>
    public interface IAccountNumber
    {
        string ToCondensedString();
        string ToExpandedString();
    }

    public class BankAccount : IAccountNumber
    {

        public string Bank { get; private set; }
        public string Branch { get; private set; }
        public string Account { get; private set; }
        public string Suffix { get; private set; }

        public BankAccount(string accountNumber)
        {
            ParseAccountNumber(accountNumber);
        }

        public BankAccount(string bank, string branch, string account, string suffix)
        {
            Bank = bank;
            Branch = branch;
            Account = account;
            Suffix = suffix;
        }

        public string ToCondensedString()
        {
            return String.Format("{0}{1}{2}{3}", Bank.PadLeft(2, '0'), Branch.PadLeft(4, '0'), Account.PadLeft(7, '0'), Suffix.PadLeft(3, '0'));
        }

        public string ToExpandedString()
        {
            return String.Format("{0}-{1}-{2}-{3}", Bank.PadLeft(2, '0'), Branch.PadLeft(4, '0'), Account.PadLeft(7, '0'), Suffix.PadLeft(3, '0'));
        }

        private void ParseAccountNumber(string accountNumber)
        {
            if (String.IsNullOrWhiteSpace(accountNumber))
                throw new InvalidDataException("Blank account number");

            accountNumber = accountNumber.Replace("-", "");

            if (accountNumber.Length < 15 || accountNumber.Length > 16)
                throw new InvalidDataException(String.Format("Needs to be a 15 or 16 character string. {0} is {1} characters", accountNumber, accountNumber.Length));

            Bank = accountNumber.Substring(0, 2);
            Branch = accountNumber.Substring(2, 4);
            Account = accountNumber.Substring(6, 7);
            Suffix = accountNumber.Substring(13, accountNumber.Length - 13);
        }
    }

    public class CreditCardAccount : IAccountNumber
    {
        public string ToCondensedString()
        {
            throw new NotImplementedException();
        }

        public string ToExpandedString()
        {
            throw new NotImplementedException();
        }
    }

    public class GIFTSCreditBatch
    {
        public const string FILETYPE = "7";
        public const string RECORDTYPEHEADER = "1";
        public const string RECORDTYPEFOOTER = "3";

        private DateTime fileCreationDate;
        private DateTime fileDueDate;
        private IAccountNumber originatorAccountNumber;

        public DateTime FileCreationDate
        {
            get { return fileCreationDate; }
            set { fileCreationDate = value; }
        }

        public DateTime FileDueDate
        {
            get { return fileDueDate; }
            set
            {
                if (HelperMethods.IsValidFileDueDate(value))
                    fileDueDate = value;
                else
                    throw new InvalidDataException("Not a valid File Due date");
            }
        }

        public IAccountNumber OriginatorAccountNumber
        {
            get { return originatorAccountNumber; }
            set { originatorAccountNumber = value; }
        }

        public bool AsBulkFile { get; set; }
        public List<GIFTSCreditRecordTransaction> Transactions { get; set; }

        public GIFTSCreditBatch(IAccountNumber ourAccount, DateTime dueDate, bool asBulkFile = false)
        {
            this.originatorAccountNumber = ourAccount;
            this.FileDueDate = dueDate;
            this.AsBulkFile = asBulkFile;
            FileCreationDate = DateTime.Now;
            Transactions = new List<GIFTSCreditRecordTransaction>();
        }

        /// <summary>
        /// Calculates the hash total to use in the footer
        /// </summary>
        /// <returns></returns>
        private string CalcHash()
        {
            long hashTotal = 0;
            foreach (GIFTSCreditRecordTransaction trans in Transactions)
            {
                string subString = trans.OtherPartyAccountNumber.ToCondensedString().Substring(2, 11);
                long asNumber = Convert.ToInt64(subString);
                hashTotal += asNumber;
            }
            hashTotal = hashTotal % 100000000000;
            string hash = hashTotal.ToString();
            hash.PadLeft(11);

            return hash;
        }

        /// <summary>
        /// Outputs to a csv.
        /// Uses the AsBulkFile property to set the file mode
        /// </summary>
        /// <returns>A string with line breaks ready to be saved to file</returns>
        public string ToCSV()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(HeaderToCSV());
            foreach (GIFTSCreditRecordTransaction trans in Transactions)
            {
                sb.AppendLine(trans.ToCSV(AsBulkFile));
            }
            sb.AppendLine(FooterToCSV());
            return sb.ToString();
        }

        private string HeaderToCSV()
        {
            string blank = "";
            StringBuilder sb = new StringBuilder();
            sb.Append(RECORDTYPEHEADER);
            sb.Append(',');
            sb.Append(blank);
            sb.Append(',');
            sb.Append(blank);
            sb.Append(',');
            sb.Append(blank);
            sb.Append(',');
            sb.Append(originatorAccountNumber.ToCondensedString());
            sb.Append(',');
            sb.Append(FILETYPE);
            sb.Append(',');
            sb.Append(FileDueDate.ToString("yyMMdd"));
            sb.Append(',');
            sb.Append(FileCreationDate.ToString("yyMMdd"));
            sb.Append(',');
            if (!AsBulkFile)
                sb.Append("I");
            return sb.ToString();
        }

        private string FooterToCSV()
        {
            int transactionAmountTotal = Transactions.Sum(t => t.TransactionAmount);
            int transactionRecordCount = Transactions.Count;
            string hashTotal = CalcHash();
            StringBuilder sb = new StringBuilder();
            sb.Append(RECORDTYPEFOOTER);
            sb.Append(',');
            sb.Append(transactionAmountTotal.ToString("000000000000"));
            sb.Append(',');
            sb.Append(transactionRecordCount.ToString("000000"));
            sb.Append(',');
            sb.Append(hashTotal.PadLeft(11, '0'));
            return sb.ToString();
        }
    }

    public class GIFTSCreditRecordTransaction
    {
        public const string RECORDTYPE = "2";

        private IAccountNumber otherPartyAccountNumber;
        private int transactionAmount;
        private string otherPartyName;
        private string otherPartyReference;
        private string otherPartyCode;
        private string otherPartyAlphaReference;
        private string otherPartyParticulars;
        private string originatorName;
        private string originatorCode;
        private string originatorReference;
        private string originatorParticulars;

        public IAccountNumber OtherPartyAccountNumber
        {
            get { return otherPartyAccountNumber; }
            set { otherPartyAccountNumber = value; }
        }
        public TransactionCodes TransactionCode;

        /// <summary>
        /// The amount in cents
        /// </summary>
        public int TransactionAmount
        {
            get { return transactionAmount; }
            set { transactionAmount = value; }
        }

        public string OtherPartyName
        {
            get { return otherPartyName; }
            set
            {
                if (value.Length > 20)
                    otherPartyName = value.Substring(0, 20);
                else
                    otherPartyName = value;
            }
        }

        public string OtherPartyReference
        {
            get { return otherPartyReference; }
            set
            {
                if (value.Length > 12)
                    otherPartyReference = value.Substring(0, 12);
                else
                    otherPartyReference = value;
            }
        }

        public string OtherPartyCode
        {
            get { return otherPartyCode; }
            set
            {
                if (value.Length > 12)
                    otherPartyCode = value.Substring(0, 12);
                else
                    otherPartyCode = value;
            }
        }

        public string OtherPartyAlphaReference
        {
            get { return otherPartyAlphaReference; }
            set
            {
                if (value.Length > 12)
                    otherPartyAlphaReference = value.Substring(0, 12);
                else
                    otherPartyAlphaReference = value;
            }
        }

        public string OtherPartyParticulars
        {
            get { return otherPartyParticulars; }
            set
            {
                if (value.Length > 12)
                    otherPartyParticulars = value.Substring(0, 12);
                else
                    otherPartyParticulars = value;
            }
        }

        public string OriginatorName
        {
            get { return originatorName; }
            set
            {
                if (value.Length > 20)
                    originatorName = value.Substring(0, 20);
                else
                    originatorName = value;
            }
        }

        public string OriginatorCode
        {
            get { return originatorCode; }
            set
            {
                if (value.Length > 12)
                    originatorCode = value.Substring(0, 12);
                else
                    originatorCode = value;
            }
        }

        public string OriginatorReference
        {
            get { return originatorReference; }
            set
            {
                if (value.Length > 12)
                    originatorReference = value.Substring(0, 12);
                else
                    originatorReference = value;
            }
        }

        public string OriginatorParticulars
        {
            get { return originatorParticulars; }
            set
            {
                if (value.Length > 12)
                    originatorParticulars = value.Substring(0, 12);
                else
                    originatorParticulars = value;
            }
        }

        public string ToCSV(bool asBulkFile)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(RECORDTYPE);
            sb.Append(",");
            sb.Append(OtherPartyAccountNumber.ToCondensedString());
            sb.Append(",");
            sb.Append(((int)TransactionCode).ToString("00"));
            sb.Append(",");
            sb.Append(TransactionAmount.ToString("000000000000"));
            sb.Append(",");
            sb.Append(OtherPartyName);
            sb.Append(",");
            sb.Append(OtherPartyReference);
            sb.Append(",");
            sb.Append(OtherPartyCode);
            sb.Append(",");
            sb.Append(OtherPartyAlphaReference);
            sb.Append(",");
            sb.Append(OtherPartyParticulars);
            sb.Append(",");
            sb.Append(OriginatorName);
            sb.Append(",");
            sb.Append(OriginatorCode);
            sb.Append(",");
            sb.Append(OriginatorReference);
            sb.Append(",");
            if (!asBulkFile)
                sb.Append(OriginatorParticulars);

            return sb.ToString();
        }
    }

}

0 个答案:

没有答案