using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Xml.Linq; using AshMind.Web.Snapshots.Handlers; namespace AshMind.Web.Snapshots.Provider { // This is somewhat ugly, but is made for a very special task. // So I followed JFHCI. public class AshMindSnapshotHandler : SnapshotHandler { private static readonly string AllowedUrlsFilePath = "~/AllowedUrlList.xml"; private static readonly HashSet AllowedUrls = new HashSet(); static AshMindSnapshotHandler() { AllowedUrlsFilePath = HttpContext.Current.Server.MapPath(AllowedUrlsFilePath); var xml = XDocument.Load(AllowedUrlsFilePath); AllowedUrls = new HashSet( xml.Element("Urls") .Elements("Url") .Select(x => x.Attribute("Value").Value) .Select(value => new Uri(value)) ); } protected override bool IsUriAllowed(Uri uri) { return base.IsUriAllowed(uri) && AllowedUrls.Contains(uri); } } }