70 lines
2.2 KiB
Plaintext
70 lines
2.2 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["Ru"] != null)
|
|
{
|
|
path = string.Format("{0}",ModExtensiones.Decripta( context.Request["Ru"]));
|
|
}
|
|
if (context.Request["FileUrl"] != null)
|
|
{
|
|
path = string.Format("{0}{1}", ModExtensiones.DirectorioBaseEmpresas, context.Request["FileUrl"]);
|
|
}
|
|
if (context.Request["P"] != null)
|
|
{
|
|
path = string.Format("{0}{1}", ModExtensiones.DirectorioBaseEmpresas,ModExtensiones.Decripta( context.Request["P"]));
|
|
}
|
|
if (path != null && path.Length>0)
|
|
{
|
|
|
|
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 ex) {
|
|
this.GuardaLog(ex.ToString());
|
|
}//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;
|
|
}
|
|
}
|
|
|
|
} |