首页 > 解决方案 > Telerik AJAX 无法上传文件

问题描述

Telerik 从 Telerik AJAX Manager v2015.1.401.45 更新到 Telerik AJAX Manager v2020.2.512.45 后无法上传文件。总是像这样的错误:

[CryptographicException: The cryptographic operation has failed!]
   Telerik.Web.UI.CryptoExceptionThrower.ThrowGenericCryptoException() +46
   Telerik.Web.UI.CryptoExceptionThrower.ThrowIfFails(Func`1 function) +46
   Telerik.Web.UI.CryptoService.CheckWhitelistTypes(Type type, String allowedCustomMetaTypes, String uploadMetaDataFullName) +116
   Telerik.Web.UI.AsyncUploadHandler.GetConfiguration(String rawData) +163
   Telerik.Web.UI.AsyncUploadHandler.EnsureSetup() +148
   Telerik.Web.UI.AsyncUploadHandler.ProcessRequest(HttpContext context) +140
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +195
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +73

标签: teleriktelerik-ajax

解决方案


该错误记录在产品文档https://docs.telerik.com/devtools/aspnet-ajax/knowledge-base/asyncupload-the-cryptographic-operation-has-failed-error-after-upgrade中。

说明 在 R1 2020 中,默认启用自定义元数据类(上传配置)白名单 - 白名单自定义元数据类型。如果您的应用程序使用此类配置,您需要将它们添加到 web.config 中的 Telerik.Upload.AllowedCustomMetaDataTypes 键。

需要添加类的全限定名,否则会得到一个 The cryptographic operation has failed!尝试上传时出错。

网络配置

<appSettings>
    <add key="Telerik.Upload.AllowedCustomMetaDataTypes" value="SomeNameSpace.SampleAsyncUploadConfiguration;SomeOtherNameSpace.OtherAsyncUploadConfiguration" />
</appSettings>

其他错误原因 如果添加 AllowedCustomMetaDataTypes 密钥或不使用自定义配置文件无法修复错误,请确保您已设置必要的加密密钥:

ConfigurationEncryptionKey ConfigurationHashKey Telerik.Web.UI.DialogParametersEncryptionKey,如果使用 RadEditor 对话框

解决方案 解决方案是将所有自定义配置类添加到 Telerik.Upload.AllowedCustomMetaDataTypes 键中,以分号; 分隔。要找出完全限定的名称,您可以使用以下列出标签中项目的方法。

ASP.NET

<asp:Label Text="Label1" ID="Label1" runat="server" />

C#

protected void Page_Load(object sender, EventArgs e)
{
    Label1.Text = typeof(MySampleAsyncUploadConfiguration).AssemblyQualifiedName.Split(',')[0];
}

为方便起见,您可以从下面的链接下载实施建议方法的 AsyncUploadGetCustomMetaDataTypes 示例项目。要使其可运行,请将 Telerik.Web.UI.dll 程序集放在项目的 bin 文件夹中。

AsyncUploadGetCustomMetaDataTypes.zip. In the project you will find two pages with two different custom handlers. As you can see, the custom handler that does not have custom configuration, does not need to have anything added to the Telerik.Upload.AllowedCustomMetaDataTypes key.


推荐阅读