57 lines
1.7 KiB
Plaintext
57 lines
1.7 KiB
Plaintext
<%@ WebHandler Language="C#" Class="SigFiles" %>
|
|
|
|
using System;
|
|
using System.Web;
|
|
using Extensiones;
|
|
|
|
public class SigFiles : IHttpHandler
|
|
{
|
|
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
//context.Response.ContentType = "text/plain";
|
|
//context.Response.Write("Hello World");
|
|
string path = "";
|
|
if (context.Request["FileUrl"] != null)
|
|
{
|
|
path = string.Format("{0}{1}", ModExtensiones.DirectorioBaseEmpresas, context.Request["FileUrl"]);
|
|
|
|
try
|
|
{
|
|
if (System.IO.File.Exists(path))
|
|
{
|
|
System.IO.FileInfo file = new System.IO.FileInfo(path);
|
|
string mimeType = "text/plain";
|
|
try
|
|
{
|
|
mimeType = MimeMapping.GetMimeMapping(path);
|
|
}
|
|
catch (Exception) { }//si truena no existe el arhivo
|
|
context.Response.Clear();
|
|
context.Response.ClearHeaders();
|
|
context.Response.ClearContent();
|
|
context.Response.AddHeader("Content-Disposition", $"attachment; filename= {Uri.EscapeDataString(file.Name)}");
|
|
context.Response.AddHeader("Content-Length", file.Length.ToString());
|
|
context.Response.ContentType = mimeType;
|
|
context.Response.Flush();
|
|
context.Response.TransmitFile(file.FullName);
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.GuardaLog(ex.ToString());
|
|
}
|
|
}
|
|
context.Response.End();
|
|
}
|
|
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
} |