Poner una etiqueta en el fichero *.ASPX en la cual visualizaremos la hora y fecha actual.
<div><h2>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</h2> </div>
En el fichero *.CS asociado (por ejemplo en el evento OnLoad)
protected void Page_Load(object sender, EventArgs e)
{ Label1.Text = DateTime.Now.ToString();
}
Nota: No olvidar los paréntesis "()" del ToString si no .. no funciona, ;)
jueves, 2 de mayo de 2013
Cómo pasar una aplicación WebForm Application .Net a WebSite
Con estos pasos me ha funcionado en mi caso:
- Crear un proyecto nuevo vacío de tipo WebSite
- Borrar todos los ficheros con extensión *.Designer
- En los ficheros *.Aspx modificar en la cabecera la directiva "codebehind" por "codefile".
- El fichero *.Cs asociado al Aspx eliminar la parte donde pone NameEspace.. (No olvidar la llave de inicio y cierre de bloque, que también deben ser eliminadas.
- Crear un proyecto nuevo vacío de tipo WebSite
- Borrar todos los ficheros con extensión *.Designer
- En los ficheros *.Aspx modificar en la cabecera la directiva "codebehind" por "codefile".
- El fichero *.Cs asociado al Aspx eliminar la parte donde pone NameEspace.. (No olvidar la llave de inicio y cierre de bloque, que también deben ser eliminadas.
Cargar un GridView de Asp.Net en tiempo de ejecución por código
Este ejemplo conecta una BD de SQLServer con un GridView de ASP.Net WebFormApplication.
Con este código podremos cargar en tiempo de ejecución un GridView.
Previamente debemos tener creada la conexión "BD" a la cual llamamos en este código en el fichero web.config de la siguiente forma:
WEB CONFIG:
<?xml version="1.0" encoding="utf-8"?
<!--
Para obtener más información sobre cómo configurar la aplicación de ASP.NET, visite
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="BD" connectionString="Data Source=NOMBRE_SERVIDOR_SQL,PUERTO INSTANCIA;Initial Catalog=NOMBRE_BASE_DATOS;Persist Security Info=True;User ID=NOMBRE_USUARIO;Password=CONTRASEÑA" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
FICHERO .CS asociado al *.ASPX (webFormApplication)
protected void Page_Load(object sender, EventArgs e)
{
//Cargamos el grid de datos
if (!IsPostBack){
SqlDataSource SqlDataSource1 = new SqlDataSource();
SqlDataSource1.ID = "SqlDataSource1";
this.Page.Controls.Add(SqlDataSource1);
SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["BD"].ConnectionString;
SqlDataSource1.SelectCommand = "SELECT top 100 Codigo, Descripcion from Articulos";
GridArticulos.DataSource = SqlDataSource1;
GridArticulos.DataBind();
}
}
Con este código podremos cargar en tiempo de ejecución un GridView.
Previamente debemos tener creada la conexión "BD" a la cual llamamos en este código en el fichero web.config de la siguiente forma:
WEB CONFIG:
<?xml version="1.0" encoding="utf-8"?
<!--
Para obtener más información sobre cómo configurar la aplicación de ASP.NET, visite
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="BD" connectionString="Data Source=NOMBRE_SERVIDOR_SQL,PUERTO INSTANCIA;Initial Catalog=NOMBRE_BASE_DATOS;Persist Security Info=True;User ID=NOMBRE_USUARIO;Password=CONTRASEÑA" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
FICHERO .CS asociado al *.ASPX (webFormApplication)
protected void Page_Load(object sender, EventArgs e)
{
//Cargamos el grid de datos
if (!IsPostBack){
SqlDataSource SqlDataSource1 = new SqlDataSource();
SqlDataSource1.ID = "SqlDataSource1";
this.Page.Controls.Add(SqlDataSource1);
SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["BD"].ConnectionString;
SqlDataSource1.SelectCommand = "SELECT top 100 Codigo, Descripcion from Articulos";
GridArticulos.DataSource = SqlDataSource1;
GridArticulos.DataBind();
}
}
martes, 30 de abril de 2013
Operadores de conjuntos en TQL EXCEPT e INTERSECT (Transact-SQL)
EXCEPT e INTERSECT (Transact-SQL)
Estos operadores se corresponden con los modelos matemáticos de unión o intersección de conjuntos.
Ejemplos
En los ejemplos siguientes se muestra cómo utilizar los operandos INTERSECT y EXCEPT. La primera consulta devuelve todos los valores de la tabla Production.Product para comparar los resultados con INTERSECT y EXCEPT.
La siguiente consulta devuelve los valores distintos devueltos por las consultas situadas a los lados izquierdo y derecho del operando INTERSECT.
La siguiente consulta devuelve los valores distintos de la consulta situados a la izquierda del operando EXCEPT que no se encuentran en la consulta derecha.
La siguiente consulta devuelve los valores distintos de la consulta situados a la izquierda del operando EXCEPT que no se encuentran en la consulta derecha. Las tablas se invierten respecto al ejemplo anterior.
Estos operadores se corresponden con los modelos matemáticos de unión o intersección de conjuntos.
Ejemplos
USE AdventureWorks2012; GO SELECT ProductID FROM Production.Product ; --Result: 504 Rows
USE AdventureWorks2012; GO SELECT ProductID FROM Production.Product INTERSECT SELECT ProductID FROM Production.WorkOrder ; --Result: 238 Rows (products that have work orders)
USE AdventureWorks2012; GO SELECT ProductID FROM Production.Product EXCEPT SELECT ProductID FROM Production.WorkOrder ; --Result: 266 Rows (products without work orders)
USE AdventureWorks2012; GO SELECT ProductID FROM Production.WorkOrder EXCEPT SELECT ProductID FROM Production.Product ; --Result: 0 Rows (work orders without products)
Fuente: http://msdn.microsoft.com/es-es/library/ms188055.aspx
jueves, 25 de abril de 2013
Trabajar en la nube. Saas, Paas o Iaas
Cuando nos referimos a desarrollar aplicaciones en la nube tenemos que puntualizar de que manera lo vamos a hacer, ya que dentro del concepto nube existen distintas formas de hacerlo que nos permiten una mayor flexibilidad o sencillez a la hora de desplegar nuestras aplicaciones o mantenerlas. Entre estas distintas formas que puede adoptar la nube se encuentran: Software-as-a-Service (SaaS), Plataform-as-a-Service (PaaS) y Infraestructure-as-a-Service (IaaS).
martes, 23 de abril de 2013
Resolve 404 in IIS Express for PUT and DELETE Verbs. Activar put y delete
Resolve 404 in IIS Express for PUT and DELETE Verbs
IIS Express is a new web server that replaces the old Visual Studio web server (aka Cassini). IIS Express provides a number of benefits which you can read about here and they key aspect is that it is IIS. However, that’s not to say that there aren’t any gotchas. One of the things that I ran into recently was that I was getting a 404 when trying to use the PUT and DELETE verbs (which are commonly used in RESTful services). The reason this is happening is because these verbs are not enabled in the mappings for the handlers by default.
To enable this is the full version of IIS, it is a relatively straight forward task using the IIS Admin tool. First you go to the Handler Mappings:

Then you select the “ExtensionlessUrlHandler-Integrated-4.0 handler:

Select “Request Restrictions”:

Then add PUT and DELETE on the “Verbs” tab:

Although the IIS Manager GUI makes this easy when using the full version of IIS, you don’t have the benefit of this GUI when working with IIS Express. But IIS Express *is* IIS so you can configure just about anything. The first thing you need to do is to find the IIS Express Configuration file. This is located in: C:\Users\<YourUserName>\Documents\IISExpress\config\applicationhost.config. Near the bottom of the file, you find the <handlers> section at this path: /configuration/location/system.webServer/handlers. Next, do a Find (Ctrl-F) for “ExtensionlessUrl-Integrated-4.0”. The final step is to add PUT and DELETE to the verb attribute:
UPDATE 8/14/2011: Some people have reported that they had to change their applicationhost.config file inside of the "C:\Program Files (x86)\IIS Express\config" directory (which does *not* match the documentation incidentally). The IIS team updated the documentation at the end of July (about 2 months after I originally posted this) here: http://learn.iis.net/page.aspx/901/iis-express-faq/ (just look for the section called "Q: How do I enable verbs like PUT/DELETE for my web application?").
To enable this is the full version of IIS, it is a relatively straight forward task using the IIS Admin tool. First you go to the Handler Mappings:
Then you select the “ExtensionlessUrlHandler-Integrated-4.0 handler:
Select “Request Restrictions”:
Then add PUT and DELETE on the “Verbs” tab:
Although the IIS Manager GUI makes this easy when using the full version of IIS, you don’t have the benefit of this GUI when working with IIS Express. But IIS Express *is* IIS so you can configure just about anything. The first thing you need to do is to find the IIS Express Configuration file. This is located in: C:\Users\<YourUserName>\Documents\IISExpress\config\applicationhost.config. Near the bottom of the file, you find the <handlers> section at this path: /configuration/location/system.webServer/handlers. Next, do a Find (Ctrl-F) for “ExtensionlessUrl-Integrated-4.0”. The final step is to add PUT and DELETE to the verb attribute:
<add name="ExtensionlessUrl-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />At this point, you should be good to go!
UPDATE 8/14/2011: Some people have reported that they had to change their applicationhost.config file inside of the "C:\Program Files (x86)\IIS Express\config" directory (which does *not* match the documentation incidentally). The IIS team updated the documentation at the end of July (about 2 months after I originally posted this) here: http://learn.iis.net/page.aspx/901/iis-express-faq/ (just look for the section called "Q: How do I enable verbs like PUT/DELETE for my web application?").
lunes, 22 de abril de 2013
Error en el servidor remoto: (404) No se encontró.
Error en el servidor remoto: (404) No se encontró.
Descripción: Excepción no controlada al ejecutar la solicitud Web actual. Revise el seguimiento de la pila para obtener más información acerca del error y dónde se originó en el código.
Detalles de la excepción: System.Net.WebException: Error en el servidor remoto: (404) No se encontró.
Error de código fuente:
El código fuente que generó esta excepción no controlada sólo se puede mostrar cuando se compila en modo de depuración. Para habilitarlo, siga uno de estos pasos y, a continuación, vuelva a solicitar la dirección URL: |
Suscribirse a:
Entradas (Atom)
Jesús Moreno - Ingeniero Ténico Informático - consultor Informático
Hola, soy Jesús Moreno Ingeniero Técnico Informático en sistemas por la US y propietario de éste blog. Mi trabajo en los ultimos años se ...
-
Para aquellos que tengáis el gusanillo de la numismática, queréis empezar a coleccionar y no podéis o no queréis hacer una gran inversión en...
-
Al intentar compartir la impresora nos lanza un error que dice: " No se pudo guardar la configuración de la impresora. No hay no hay m...
-
En una consulta LINQ que no devuelve ningún resultado y utilizamos la función First() se presenta la excepcion, “InvalidOperationException:...
