Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Telerik RadPersistenceManager无法读取存储内容_C#_Asp.net_Telerik_Telerik Grid - Fatal编程技术网

C# Telerik RadPersistenceManager无法读取存储内容

C# Telerik RadPersistenceManager无法读取存储内容,c#,asp.net,telerik,telerik-grid,C#,Asp.net,Telerik,Telerik Grid,我已将RadPersistenceManager与asp.net一起使用,并遵循以下指南: 但当我在项目中实现此功能时,会出现以下异常: 标题:xxxx.aspx,xxxxx方法名称: 无法读取存储内容。找不到文件 'C:\inetpub\wwwroot\XXXX\App\u Data\TelerikAspNetRadControlsPersistedState' 例外情况:在 Telerik.Web.UI.PersistenceFramework.AppDataStorageProvider

我已将RadPersistenceManager与asp.net一起使用,并遵循以下指南:

但当我在项目中实现此功能时,会出现以下异常:

标题:xxxx.aspx,xxxxx方法名称: 无法读取存储内容。找不到文件 'C:\inetpub\wwwroot\XXXX\App\u Data\TelerikAspNetRadControlsPersistedState'

例外情况:在 Telerik.Web.UI.PersistenceFramework.AppDataStorageProvider.LoadStateFromStorage(字符串 GraphicalUserInterface.Jobbark.LoadGridJobbark()的Telerik.Web.UI.RadPersistenceManager.LoadState()中的


这是默认的存储提供程序密钥。如果控件正在查找它,则您的自定义提供程序根本无效

确保您拥有演示的所有内容,主要包括:

设置自定义存储提供程序的行:

protected void Page_Init(object sender, EventArgs e)
{
    RadPersistenceManager1.StorageProviderKey = CookieName;
    RadPersistenceManager1.StorageProvider = new CookieStorageProvider(CookieName);
}
以及自定义存储提供程序本身:

using System;
using System.Linq;
using System.Web;
using Telerik.Web.UI.PersistenceFramework;
using System.IO;
using System.IO.Compression;
using System.Text;

public class CookieStorageProvider : IStateStorageProvider
{
    private static readonly Encoding AsciiEncoding = System.Text.Encoding.ASCII;
    private static readonly int MaxCookieSize = 4000;
    private static readonly int LengthDataByteCount = sizeof(Int32);
    private string StorageKey { get; set; }

    #region IStateStorageProvider

    public CookieStorageProvider(string key)
    {
        StorageKey = key;
    }

    public void SaveStateToStorage(string key, string serializedState)
    {
        HttpCookie cookie = new HttpCookie(StorageKey);
        string settingsData = CompressString(serializedState);

        if (settingsData.Length > MaxCookieSize)
        {
            throw new ArgumentOutOfRangeException("Current settings exceed 4k in compressed form! Operation canceled!");
        }

        cookie.Value = settingsData;

        HttpContext.Current.Response.Cookies.Add(cookie);
    }

    public string LoadStateFromStorage(string key)
    {
        return DecompressString(HttpContext.Current.Request.Cookies[StorageKey].Value.ToString());
    }

    #endregion

    private string CompressString(string inputString)
    {
        byte[] outputBytes = null;
        byte[] inputBytes = AsciiEncoding.GetBytes(inputString);

        using (MemoryStream ms = new MemoryStream())
        {
            using (GZipStream zipStream = new GZipStream(ms, CompressionMode.Compress))
            {
                zipStream.Write(inputBytes, 0, inputBytes.Length);
            }
            outputBytes = ms.ToArray();
        }

        return Convert.ToBase64String(AddDataCount(outputBytes, inputBytes.Length));
    }

    private string DecompressString(string inputString)
    {
        string outputString = String.Empty;
        byte[] inputBytes = Convert.FromBase64String(inputString);
        Int32 lengthDataArray = BitConverter.ToInt32(inputBytes, inputBytes.Length - LengthDataByteCount);
        byte[] outputBytes = new byte[lengthDataArray];

        using (MemoryStream ms = new MemoryStream(RemoveDataCount(inputBytes)))
        {
            using (GZipStream zipStream = new GZipStream(ms, CompressionMode.Decompress))
            {
                zipStream.Read(outputBytes, 0, outputBytes.Length);
            }
            outputString = AsciiEncoding.GetString(outputBytes);
        }

        return outputString;
    }

    private byte[] AddDataCount(byte[] inputArray, Int32 length)
    {
        byte[] lengthDataArray = BitConverter.GetBytes(length);
        Array.Resize<byte>(ref inputArray, inputArray.Length + LengthDataByteCount);
        Array.Copy(lengthDataArray, 0, inputArray, inputArray.Length - LengthDataByteCount, LengthDataByteCount);
        return inputArray;
    }

    private byte[] RemoveDataCount(byte[] inputArray)
    {
        Array.Resize<byte>(ref inputArray, inputArray.Length - LengthDataByteCount);
        return inputArray;
    }
}
使用系统;
使用System.Linq;
使用System.Web;
使用Telerik.Web.UI.PersistenceFramework;
使用System.IO;
使用系统IO压缩;
使用系统文本;
公共类CookieStorageProvider:IStateStorageProvider
{
私有静态只读编码ascienceoding=System.Text.Encoding.ASCII;
私有静态只读int MaxCookieSize=4000;
私有静态只读int LengthDataByteCount=sizeof(Int32);
私有字符串StorageKey{get;set;}
#区域IStateStorageProvider
公共CookieStorageProvider(字符串键)
{
StorageKey=key;
}
public void SaveStateToStorage(字符串键、字符串序列化状态)
{
HttpCookie cookie=新的HttpCookie(StorageKey);
字符串设置数据=压缩字符串(序列化数据状态);
如果(设置数据长度>最大CookieSize)
{
抛出新ArgumentOutOfRangeException(“当前设置在压缩格式中超过4k!操作已取消!”);
}
cookie.Value=设置数据;
HttpContext.Current.Response.Cookies.Add(cookie);
}
公共字符串LoadStateFromStorage(字符串键)
{
返回解压缩字符串(HttpContext.Current.Request.Cookies[StorageKey].Value.ToString());
}
#端区
私有字符串压缩字符串(字符串输入字符串)
{
byte[]outputBytes=null;
byte[]inputBytes=AscienceODing.GetBytes(inputString);
使用(MemoryStream ms=new MemoryStream())
{
使用(GZipStream zipStream=新的GZipStream(ms,CompressionMode.Compress))
{
zipStream.Write(inputBytes,0,inputBytes.Length);
}
outputBytes=ms.ToArray();
}
返回Convert.ToBase64String(AddDataCount(outputBytes,inputBytes.Length));
}
私有字符串解压缩字符串(字符串输入字符串)
{
string outputString=string.Empty;
byte[]inputBytes=Convert.FromBase64String(inputString);
Int32 lengthDataArray=BitConverter.ToInt32(inputBytes,inputBytes.Length-LengthDataByteCount);
字节[]输出字节=新字节[lengthDataArray];
使用(MemoryStream ms=新的MemoryStream(RemoveDataCount(inputBytes)))
{
使用(GZipStream zipStream=新的GZipStream(ms,CompressionMode.decompresse))
{
读取(outputBytes,0,outputBytes.Length);
}
outputString=ascienceoding.GetString(outputBytes);
}
返回输出字符串;
}
专用字节[]AddDataCount(字节[]输入阵列,Int32长度)
{
byte[]lengthDataArray=BitConverter.GetBytes(长度);
调整数组大小(ref-inputArray,inputArray.Length+LengthDataByteCount);
复制(lengthDataArray,0,inputArray,inputArray.Length-LengthDataByteCount,LengthDataByteCount);
返回输入;
}
专用字节[]RemoveDataCount(字节[]输入阵列)
{
Resize(ref-inputArray,inputArray.Length-LengthDataByteCount);
返回输入;
}
}

演示和我的示例的不同之处在于,我需要在页面加载而不是加载按钮上加载持久性配置。因此,有时CookieStorageProvider似乎没有在Page_Init中启动,因此我将其添加到Page_load中。

请发布导致此错误的代码。除了母版页中有RadScriptManager外,上述指南中的代码相同。