Mejores Prácticas en ASP.NET y AJAX Jose Manuel Alarcón Isabel Gómez Krasis - campusMVP Director http://www.jasoft.org Microsoft Development Advisor isabelg@microsoft.com 1
Agenda Mejores Prácticas en ASP.NET Mejores Prácticas en Ajax Uso de Cache Usar Modelo Asíncrono Ahorro de Recursos Mejores Prácticas en Ajax
Mejores Prácticas en ASP.NET 3
Mejores Prácticas en ASP.NET Caché de Información 3/24/2017 3:59 PM Se trata de almacenar información usada con frecuencia y costosa de obtener para minimizar la carga de procesamiento. Ventajas: mucho menos costoso y más rápido. Objetivos: Rendimiento, escalabilidad y disponibilidad. Tipos de caché: De cliente De servidor Declarativa Caché completa (páginas y controles) Caché parcial Por código MICROSOFT CONFIDENTIAL © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Mejores Prácticas en ASP.NET Caché declarativa 3/24/2017 3:59 PM Se trata de guardar en el servidor (generalmente) los resultados de procesar una determinada página o control de usuario. Se emplea la directiva <%@ OutputCache %> en la parte superior de la página o control de usuario. Páginas/controles completos: VaryByParam: se hace caché en función de un parámetro de la URL. VaryByHeader: se cachea en función de una cabecera del navegador. VaryByControl: se hace caché del contenido de un control o controles. VaryBycustom: el parámetro que hace variar la caché es arbitrario y definido por el programador. Porciones de páginas: controles de usuario VaryByControl: varía la caché en función de una propiedad del control. OJO: Shared = True PostCacheSubstitution MICROSOFT CONFIDENTIAL © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Mejora del rendimiento con Caché declarativa 6
Mejores Prácticas en ASP.NET Caché por Código 3/24/2017 3:59 PM Se puede establecer caché en memoria sin asignarla a la salida de una página o control. Para ello empleamos la clase System.Web.Caching.Cache Se maneja de manera similar a una colección. Permite definir duración absoluta, relativa o prorogada Lo más interesante: prioridades y dependencias Archivos Otras claves de caché Tiempo Bases de datos SQL Server Dependencias personalizadas MICROSOFT CONFIDENTIAL © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Mejores Prácticas en ASP.NET Usar Modelo Asíncrono HTTPHandlers Asíncronos HTTPModules Asíncronos Páginas Asíncronas
Mejores Prácticas en ASP.NET Optimización de Recursos Debug=false en web.config Acceso a Datos Paginación inteligente (ObjectDataSource) Connection Pooling Optimizar el uso de objeto de Sesión Viewstate (Deshabilitar si no es necesario)
Mejores Prácticas en ASP.NET Uso Juicioso de Viewstate 3/24/2017 3:59 PM ViewState Conserva el estado de los controles de la página entre idas y venidas al servidor. Se envía entre el cliente y el servidor y viceversa en cada Postback de la página. Si tenemos muchos controles puede llegar a ser realmente grande. CONSEJO: deshabilitar el ViewState en los controles que no lo necesiten. Ej: etiquetas, rejillas que se regeneran, etc… TÉCNICA AVANZADA: almacenar el ViewState en el servidor: Ventaja: No hay que moverlo por la Red Inconveniente: puede ocupar mucha memoria si abusamos. MICROSOFT CONFIDENTIAL © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Almacenamiento del ViewState en el Servidor 11
Mejores Prácticas en AJAX 12
Mejores Prácticas en AJAX AJAX Concepto Beneficios: Mejora de la experiencia de Usuario Optimización en el uso del Ancho de Banda Renderización Parcial Llamada ligera a Servicios Web Facilita la programación de código de cliente
Mejores Prácticas en AJAX Microsoft ASP.NET AJAX Server Framework ASP.NET 2.0 Application Services Page Framework, Server Controls ASP.NET Pages Web Services (ASMX or WCF) Client Framework HTML markup, CSS, and Script “Ajax” Service Proxies Microsoft Ajax Library ASP.NET 2.0 Ajax Extensions Componentes (Non-visual, Behaviours, controles) Ajax-Enabled Server Controls App Services Bridge Networking Layer Web Services Bridge Base Class Library Core Services Browser Compatibility
Mejores Prácticas en AJAX ASP.NET AJAX Toolkit y Futures ASP.NET AJAX Futures ASP.NET AJAX Control Toolkit Components Visual Studio 2005 Templates ASP.NET AJAX Control Toolkit Base Classes (.NET & JavaScript) ASP.NET AJAX Server Extensions Components ASP.NET AJAX Library Framework ASP.NET 2.0
“Ajaxificando” 16
Mejores Prácticas en AJAX DEMO: Visor de Fotos <asp:UpdatePanel> <asp:UpdatePanel> <asp:UpdateProgress> Trigger
Mejores Prácticas en AJAX Optimizando Ficheros de script en Sistema de Ficheros UpdatePanel con UpdateMode=Conditional Debug=false Ajax Patterns(http://ajaxpatterns.org) Indicios Visuales del cambio Navegación Lógica y URLs únicos
Optimizando el uso de Ajax 19
Mejores Prácticas en ASP.NET y AJAX Recapitulación y Conclusiones ASP.NET + AJAX: Seguras Escalables Uso de Cache Modelo Asíncrono Ahorro de Recursos Experiencia de usuario (AJAX)
Referencias ASP.NET Seguridad: Rendimiento: Improving Web Application Security Threats and Countermeasures An Introductory Guide to Building and Deploying More Secure Sites with ASP.NET and IIS An Introductory Guide to Building and Deploying More Secure Sites with ASP.NET and IIS, Part 2 Rendimiento: 10 Tips for Writing High-Performance Web Applications Asynchronous Pages in ASP.NET 2.0 Power Programming Tips for ASP.NET 2.0 Developing High-Performance ASP.NET Applications State Management Recommendations
Referencias AJAX Blogs Patterns: http://AJAX.asp.net/ http://forums.asp.net/default.aspx?GroupID=34 Blogs http://www.jasoft.org – José Manuel Alarcón http://smarx.com – Steve Marx http://nikhilk.net – Nikhil Kothari http://weblogs.asp.net/scottgu – Scott Guthrie Patterns: http://ajaxpatterns.org
23