diff --git a/Business/Business.csproj b/Business/Business.csproj index 454fbe09..37b5e782 100644 --- a/Business/Business.csproj +++ b/Business/Business.csproj @@ -59,6 +59,9 @@ ..\packages\EPPlus.4.5.3.3\lib\net40\EPPlus.dll + + ..\WebLab\Bin\HtmlSanitizationLibrary.dll + False ..\Referencias\Iesi.Collections.dll diff --git a/Business/Utility.cs b/Business/Utility.cs index 5518d367..acbe69d3 100644 --- a/Business/Utility.cs +++ b/Business/Utility.cs @@ -14,6 +14,7 @@ //using Sql.Data using System.Security.Cryptography; +using Microsoft.Security.Application; using OfficeOpenXml; using System.Drawing; using OfficeOpenXml.Style; @@ -890,8 +891,8 @@ public static void ExportDataTableToXlsx(DataTable dataTable, string filename) HttpResponse response = HttpContext.Current.Response; - // Color finalBackColor = ColorTranslator.FromHtml("#2b3e4c"); //azul-neuquen - // Color fontColor = Color.White + // Color finalBackColor = ColorTranslator.FromHtml("#2b3e4c"); //azul-neuquen + // Color fontColor = Color.White using (ExcelPackage package = new ExcelPackage()) { // Crear una nueva hoja de trabajo @@ -1005,7 +1006,7 @@ out numero worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); //Todas las celdas - var range2 = worksheet.Cells[1, 1, rowCount+1, colCount]; //row+1 asi cuenta la fila del encabezado. + var range2 = worksheet.Cells[1, 1, rowCount + 1, colCount]; //row+1 asi cuenta la fila del encabezado. ExcelBordes(range2); // --- CONFIGURAR RESPUESTA HTTP --- response.Clear(); @@ -1024,7 +1025,7 @@ out numero } } - + private static void ExcelEstilo(ExcelRange range, Color? backColor = null, Color? fontColor = null) { Color finalBackColor = backColor ?? Color.Transparent; @@ -1053,7 +1054,7 @@ private static void ExcelBordes(ExcelRange rango) public static void ExportGridViewToExcel(GridView grid, string nombreArchivo) { - if(grid.Rows.Count > 0) + if (grid.Rows.Count > 0) { using (var package = new ExcelPackage()) { @@ -1105,7 +1106,7 @@ public static void ExportGridViewToExcel(GridView grid, string nombreArchivo) fila++; } //Todas las celdas - var range2 = ws.Cells[1, 1, grid.Rows.Count + 1, grid.Columns.Count]; + var range2 = ws.Cells[1, 1, grid.Rows.Count + 1, grid.Columns.Count]; ExcelBordes(range2); // Autoajustar columnas ws.Cells[1, 1, fila - 1, grid.Columns.Count].AutoFitColumns(); @@ -1114,7 +1115,7 @@ public static void ExportGridViewToExcel(GridView grid, string nombreArchivo) // 2.2) Escribir filas del footer // ================================ - GridViewRow filaFooter = grid.FooterRow; + GridViewRow filaFooter = grid.FooterRow; col = 1; if (tieneValores(filaFooter.Cells)) @@ -1128,7 +1129,7 @@ public static void ExportGridViewToExcel(GridView grid, string nombreArchivo) ws.Cells[fila, col].Style.Font.Color.SetColor(fontColor); col++; } - ExcelBordes(ws.Cells[grid.Rows.Count + 2,1, grid.Rows.Count + 2,col-1 ]); + ExcelBordes(ws.Cells[grid.Rows.Count + 2, 1, grid.Rows.Count + 2, col - 1]); } // ================================ @@ -1144,9 +1145,9 @@ public static void ExportGridViewToExcel(GridView grid, string nombreArchivo) response.End(); } } - + } - private static bool tieneValores(TableCellCollection footer) + private static bool tieneValores(TableCellCollection footer) { foreach (TableCell cell in footer) @@ -1161,7 +1162,7 @@ private static bool tieneValores(TableCellCollection footer) private static void ExcelCompletarFilas(ExcelWorksheet ws, TableCell cell, int fila, int col, Color? encabezadoColor = null, Color? fontColor = null) { - + // (1) Detectar si es número // Detectar números por TryParse double numero; @@ -1228,17 +1229,17 @@ out numero { ws.Cells[fila, col].Style.Font.Color.SetColor(cell.ForeColor); } - + ws.Cells[fila, col].Style.Font.Size = 9; - + } public static void GenerarColumnasGrid(GridView grid, DataTable dt) { - if(dt.Columns.Count > 0) + if (dt.Columns.Count > 0) { DataColumnCollection dc = dt.Columns; - foreach(DataColumn column in dc) + foreach (DataColumn column in dc) { BoundField columna = new BoundField(); columna.HeaderText = column.ColumnName; @@ -1247,5 +1248,42 @@ public static void GenerarColumnasGrid(GridView grid, DataTable dt) } } #endregion + #region textoEnriquecido + + /// + /// Sanitiza un texto HTML para eliminar contenido potencialmente peligroso. + /// + /// + /// Instancia de utilizada para decodificar el contenido HTML. + /// + /// + /// Texto HTML recibido desde el cliente. + /// + /// + /// Devuelve el HTML sanitizado y seguro para almacenar o mostrar. + /// + + public string SanitizarHTML(HttpServerUtility server, string texto) + { + // Leer HTML sin que ASP.NET lo bloquee + string html = server.UrlDecode(texto); + // Sanitizar + string limpio = Sanitizer.GetSafeHtmlFragment(html); + //Despu�s del sanitizado, decodific� entidades HTML: + limpio = HttpUtility.HtmlDecode(limpio); + + return limpio; + } + + public string PasarHTMLaPlano(HttpServerUtility server, string texto) + { + string html = server.UrlDecode(texto); + + string textoPlano = Regex.Replace(html, "<.*?>", string.Empty); + + return HttpUtility.HtmlDecode(textoPlano).Trim(); + } + + #endregion } } \ No newline at end of file diff --git a/WebLab/Items/ItemEdit2.aspx b/WebLab/Items/ItemEdit2.aspx index 3a203408..ee0666f4 100644 --- a/WebLab/Items/ItemEdit2.aspx +++ b/WebLab/Items/ItemEdit2.aspx @@ -1,35 +1,45 @@ <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ItemEdit2.aspx.cs" Inherits="WebLab.Items.ItemEdit2" MasterPageFile="~/Site1.Master" %> - <%@ Register assembly="Anthem" namespace="Anthem" tagprefix="anthem" %> -<%--<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %> ---%> - - - - - + - - - - + + + + + + + - + +