public override FileInfo GetRequestedFileInfo(HttpContext context) { config = hapConfig.Current; string path = HttpUtility.UrlDecode(RoutingPath.Replace('^', '&').Replace("|", "%")); DriveMapping unc = config.MyFiles.Mappings.FilteredMappings[RoutingDrive.ToCharArray()[0]]; if (unc == null || !isAuth(unc)) { context.Response.Redirect(VirtualPathUtility.ToAbsolute("~/unauthorised.aspx"), true); } else { path = Converter.FormatMapping(unc.UNC, ADUser) + '\\' + path.Replace('/', '\\'); } return(new FileInfo(path)); }
public void ProcessRequest(HttpContext context) { hapConfig config = hapConfig.Current; User user = new User(); if (config.AD.AuthenticationMode == Web.Configuration.AuthMode.Forms) { HttpCookie token = HttpContext.Current.Request.Cookies["token"]; if (token == null) { throw new AccessViolationException("Token Cookie Missing, user not logged in correctly"); } user.Authenticate(HttpContext.Current.User.Identity.Name, TokenGenerator.ConvertToPlain(token.Value)); } user.ImpersonateContained(); try { Context = context; config = hapConfig.Current; DriveMapping unc; string path = Converter.DriveToUNC(RoutingPath.Replace('^', '&'), RoutingDrive, out unc, ((HAP.AD.User)Membership.GetUser())); FileInfo file = new FileInfo(path); Image thumb; try { Bitmap b = new ShellThumbnail().GetThumbnail(file.FullName); thumb = b;// FixedSize(b, 64, 64); if (thumb == null) { throw new NullReferenceException(); } } catch { FileStream fs = file.OpenRead(); Image image = Image.FromStream(fs); thumb = FixedSize(image, 64, 64); image.Dispose(); fs.Close(); fs.Dispose(); } MemoryStream m = new MemoryStream(); thumb.Save(m, ImageFormat.Png); context.Response.Clear(); context.Response.ExpiresAbsolute = DateTime.Now; context.Response.ContentType = Converter.MimeType(".png"); context.Response.Buffer = true; context.Response.AppendHeader("Content-Disposition", "inline; filename=\"" + file.Name + "\""); context.Response.AppendHeader("Content-Length", m.Length.ToString()); context.Response.Clear(); m.WriteTo(context.Response.OutputStream); context.Response.Flush(); file = null; user.EndContainedImpersonate(); } catch { DriveMapping unc; string path = Converter.DriveToUNC(RoutingPath.Replace('^', '&'), RoutingDrive, out unc, ((HAP.AD.User)Membership.GetUser())); FileInfo file = new FileInfo(path); string Icon = HAP.MyFiles.File.ParseForImage(file); user.EndContainedImpersonate(); if (Icon.EndsWith(".ico")) { context.Response.Redirect(VirtualPathUtility.ToAbsolute("~/api/mycomputer/" + Icon)); } else { context.Response.Redirect(VirtualPathUtility.ToAbsolute("~/images/icons/" + Icon)); } } }