vendredi 6 mars 2015

Security Exception webservice

in my website http://ift.tt/1EvwneC i use web service .ashx for thumb images and it's work in local but in host no.


Security Exception


Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.


Exception Details: System.Security.SecurityException: System.Security.Permissions.SecurityPermission



var photo = ImageToByte(finalImage);
var factory = (IWICComponentFactory)new WICImagingFactory();
var inputStream = factory.CreateStream();
inputStream.InitializeFromMemory(photo, (uint)photo.Length);
var decoder = factory.CreateDecoderFromStream(inputStream, null, WICDecodeOptions.WICDecodeMetadataCacheOnLoad);
var frame = decoder.GetFrame(0);
// Compute target size
uint thumbWidth, thumbHeight;
thumbWidth =Convert.ToUInt32( photowidth);
thumbHeight = Convert.ToUInt32(photoheight) ;
// Prepare output stream to cache file
var outputStream = new MemoryIStream();
// Prepare JPG encoder
var encoder = factory.CreateEncoder(Consts.GUID_ContainerFormatJpeg, null);
encoder.Initialize(outputStream, WICBitmapEncoderCacheOption.WICBitmapEncoderNoCache);
// Prepare output frame
IWICBitmapFrameEncode outputFrame;
var arg = new IPropertyBag2[1];
encoder.CreateNewFrame(out outputFrame, arg);
var propBag = arg[0];
var propertyBagOption = new PROPBAG2[1];
propertyBagOption[0].pstrName = "ImageQuality";
propBag.Write(1, propertyBagOption, new object[] { 0.85F });
outputFrame.Initialize(propBag);
outputFrame.SetResolution(96, 96);
outputFrame.SetSize(thumbWidth, thumbHeight);
// Prepare scaler
var scaler = factory.CreateBitmapScaler();
scaler.Initialize(frame, thumbWidth, thumbHeight, WICBitmapInterpolationMode.WICBitmapInterpolationModeFant);
// Write the scaled source to the output frame
outputFrame.WriteSource(scaler, new WICRect { X = 0, Y = 0, Width = (int)thumbWidth, Height = (int)thumbHeight });
outputFrame.Commit();
encoder.Commit();
var outputArray = outputStream.ToArray();
outputStream.Close();

var cachePolicy = context.Response.Cache;
cachePolicy.SetCacheability(HttpCacheability.Public);
cachePolicy.SetOmitVaryStar(true);
cachePolicy.SetExpires(DateTime.Now + TimeSpan.FromDays(365));
cachePolicy.SetValidUntilExpires(true);
cachePolicy.SetLastModified(File.GetLastWriteTime(photoPath));
// Write to the cache file
//File.WriteAllBytes(photoCachePath, outputArray);
// Write to the response
context.Response.ContentType = "image/jpg";
context.Response.OutputStream.Write(outputArray, 0, outputArray.Length);


show error for this



var factory = (IWICComponentFactory)new WICImagingFactory();




Aucun commentaire:

Enregistrer un commentaire