Ignore SSL certificate errors for image URLs used in Image Editor..

This fixes issues with local development on SSL-enabled site with self-signed certificates.
Ignoring certificate errors is usually not the wisest thing to do, but we're dealing with locally stored images here only.
This commit is contained in:
Piotr Szmyd
2015-01-30 20:02:44 +01:00
parent 73bc34a93e
commit dd9e4ad3e9

View File

@@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.ImageEditor.Models;
@@ -98,14 +99,21 @@ namespace Orchard.ImageEditor.Controllers {
if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent))
return HttpNotFound();
var sslFailureCallback = new RemoteCertificateValidationCallback((o, cert, chain, errors) => true);
using (var wc = new WebClient()) {
try {
ServicePointManager.ServerCertificateValidationCallback += sslFailureCallback;
var data = wc.DownloadData(url);
return new FileContentResult(data, "image");
}
catch {
return HttpNotFound();
}
finally {
ServicePointManager.ServerCertificateValidationCallback -= sslFailureCallback;
}
}
}
}