对庞大数据集的每个数据行进行操作会使网页变慢。分页是好的选择吗?

Doing operations on each datarow of a huge dataset make a webpage slow. Is paging good option?

我正在处理的遗留应用程序,returns 网格上的巨大数据集(不要问为什么)并且还具有将其导出到 excel 的功能。

我正在加密(使用 C# 方法:下面的代码)数据库中的一些数据,并在该页面上的网格中读取数据集时对其进行解密。早些时候报告在大约 15 秒内生成,但现在它只是超时并继续......

似乎是因为对所有这些记录进行了解密,有没有更好的方法来做到这一点?

#region Encryption-Decryption Methods
public static string Encrypt(string TextFromForm)
{
    byte[] encryptedBytes = null;
    byte[] BytesToBeEncrypted = null;
    if (TextFromForm != null)
    {
        BytesToBeEncrypted = Encoding.Unicode.GetBytes(TextFromForm);
    }
    string EncryptionKeyPassword = "********";
    // The salt bytes must be at least 8 bytes/ setting salt is mandatory for AES
    byte[] saltBytes = Encoding.ASCII.GetBytes("********");

    try
    {
        using (MemoryStream ms = new MemoryStream())
        {
            using (AesManaged AES = new AesManaged())
            {
                AES.Padding = PaddingMode.PKCS7;
                AES.KeySize = 256;
                AES.BlockSize = 128; //half of key size : can be changed if needed

                // we can pass the key as a parameter to the method.
                var key = new Rfc2898DeriveBytes(EncryptionKeyPassword, saltBytes); // generates the key with the password and salt
                AES.Key = key.GetBytes(AES.KeySize / 8);
                AES.IV = key.GetBytes(AES.BlockSize / 8);

                AES.Mode = CipherMode.CBC; // Cipher block Chaining 

                using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(BytesToBeEncrypted, 0, BytesToBeEncrypted.Length);
                    cs.Close();
                }
                encryptedBytes = ms.ToArray();

            }
        }
        return System.Text.Encoding.GetEncoding(1252).GetString(encryptedBytes); // returning string from encrypted bytes
    }
    catch (Exception ex)
    {
        string encryptionmessage = ex.Message;
    }
    return System.Text.Encoding.GetEncoding(1252).GetString(encryptedBytes);
}

public static string Decrypt(string EncryptedText)
    {
        byte[] decryptedBytes = null;
        string EncryptionKeyPassword = "*********";
        byte[] BytesToBeDecrypted = null;
        if (String.IsNullOrEmpty(EncryptedText))
        {
            EncryptedText = "";
        }
        BytesToBeDecrypted = System.Text.Encoding.GetEncoding(1252).GetBytes(EncryptedText); // decoding bytes from encrypted text

        // The salt bytes must be at least 8 bytes. setting salt is mandatory in AES
        byte[] saltBytes = Encoding.ASCII.GetBytes("*********");

        try
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (AesManaged AES = new AesManaged())
                {
                    AES.Padding = PaddingMode.PKCS7;
                    AES.KeySize = 256;
                    AES.BlockSize = 128;

                    // we can pass the key as a parameter to the method instead of generating.
                    var key = new Rfc2898DeriveBytes(EncryptionKeyPassword, saltBytes); // generates the key with the password and salt
                    AES.Key = key.GetBytes(AES.KeySize / 8);
                    AES.IV = key.GetBytes(AES.BlockSize / 8);

                    AES.Mode = CipherMode.CBC;

                    using (var cs = new CryptoStream(ms, AES.CreateDecryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(BytesToBeDecrypted, 0, BytesToBeDecrypted.Length);
                        cs.Close();
                    }
                    decryptedBytes = ms.ToArray();

                }
            }
            string TextFromDB = Encoding.Unicode.GetString(decryptedBytes);
            return TextFromDB;
        }
        catch (Exception ex)
        {
            string decryptionmessage = ex.Message;
        }
        return string.Empty;
    }
#endregion

谢谢大家,其实我每次调用加密解密的方法都在生成Key和IV,所以执行起来很费时间。 通过在 session_start 生成密钥,我可以在任何地方使用它并减少加密和解密时间。