对一个巨大数据集的每个数据库进行操作会使网页缓慢。分页好选择? [英] Doing operations on each datarow of a huge dataset make a webpage slow. Is paging good option?

查看:126
本文介绍了对一个巨大数据集的每个数据库进行操作会使网页缓慢。分页好选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

a legacy application that I am working on, returns a huge dataset on a grid (dont ask why) and also has a feature to export it to excel.

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

I am encrypting(using C# methods : code below) some of that data in databse and decrypting it while the dataset is read in grid on that page. Earlier the report was generated in around 15 seconds but now it just times out and keeps on going..

似乎是因为在所有这些记录上都发生了解密,是有更好的方法吗?

It seems to be because of decryption happening on all those records, is there a better way to do that?

#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


推荐答案

感谢所有,实际上,我每次被调用时,一直在加密和解密的方法中生成密钥和IV,因此执行时间很长。 通过在session_start生成密钥,我可以在任何地方使用它,并减少加密和解密时间。

Thanks All, Actually I had been generating the Key and IV in the method of Encryption and Decryption everytime they were called, so it was taking a lot of time to execute. By generating the key at session_start, I was able to use it everywhere and reduce encryption and decryption time.

这篇关于对一个巨大数据集的每个数据库进行操作会使网页缓慢。分页好选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆