ASP.NET信任级别异常



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

错误:安全异常

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

异常详细信息:System.Security.SecurityException:请求类型为"System.Security.Permissions.MediaPermission,WindowsBase,Version=3.0.0,Culture=neutral,PublicKeyToken=31bf3856a364e35"的权限失败。

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;
}

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/

最新更新