TFS_ANTIGUO/SIGPC/ProyectoSIGPC/handlers/PrepararFirma.ashx

79 lines
2.3 KiB
Text
Raw Permalink Normal View History

<%@ WebHandler Language="C#" Class="PrepararFirma" %>
using FirmaDigitalAv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
public class PrepararFirma : IHttpHandler, System.Web.SessionState.IRequiresSessionState {
public void ProcessRequest(HttpContext context)
{
string errorMsg = string.Empty;
string dataToSign = string.Empty;
// parameters
string FormXML = context.Request["FormXML"];
string Certificate = context.Request["Certificate"];
try
{
using (FirmaDigitalAvSvcClient cliente = new FirmaDigitalAvSvcClient())
{
if (cliente.PrepararFirmaDigitalCades(
FormXML,
Certificate,
EsXp(context),
out dataToSign,
out errorMsg
))
{
context.Response.Clear();
context.Response.ContentType = "application/xml";
context.Response.Write(dataToSign);
}
else
{
context.Response.Clear();
context.Response.ContentType = "text/plain";
context.Response.Write(errorMsg);
}
}
}
catch (Exception e)
{
errorMsg = "Falló el llamado al servidor de firma digital";
while (e != null)
{
errorMsg += (string.IsNullOrEmpty(errorMsg) ? "" : ": ") + e.Message;
e = e.InnerException;
}
context.Response.Clear();
context.Response.ContentType = "text/plain";
context.Response.Write(errorMsg);
}
}
/// <summary>
/// Retorna true si el sistema operativo cliente es Windows XP
/// </summary>
private static bool EsXp(HttpContext context)
{
return context.Request.UserAgent.ToUpper().IndexOf("WINDOWS NT 5.1") > 0;
}
public bool IsReusable
{
get
{
return false;
}
}
}