ASP.NET信任级别异常

时间:2013-06-23 14:52:20

标签: asp.net ckeditor

它在我的本地系统上运行正常。但不是在现场。我用这个代码块用ckeditor上传图像。我打电话给主机提供商我必须用信任级别中等或高来编写这些代码。托管公司不支持信任级别。如果我可以使用web.config完全更改信任级别,它可以正常工作。如何编写或更改支持高或中等信任级别的代码。

错误:安全例外

描述:应用程序尝试执行安全策略不允许的操作。要授予此应用程序所需的权限,请与您的系统管理员联系或在配置文件中更改应用程序的信任级别。

异常详细信息:System.Security.SecurityException:对“System.Security.Permissions.MediaPermission,WindowsBase,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35”类型的权限的请求失败。

public static ImageMedia Create(byte[] data)
{
    ImageMedia result = new ImageMedia();
    result._source = BitmapDecoder.Create(new MemoryStream(data), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None).Frames[0];
    result._data = data;
    try { result._copyright = ((BitmapMetadata)result._source.Metadata).Copyright; }
    catch (Exception) { }
    return result;
}

1 个答案:

答案 0 :(得分:0)

3.0方式需要完全信任。您可以尝试从较低级别的位图获取信息

Bitmap MyPhoto =
    new Bitmap(@"myphoto.JPG");
PropertyItem[] props =
    MyPhoto.PropertyItems;
foreach (PropertyItem prop in props)
{
    MessageBox.Show(
        prop.Id.ToString());
}

阅读本文了解更多详情:http://www.developerfusion.com/article/84474/reading-writing-and-photo-metadata/

相关问题