sábado, 30 de abril de 2011

Basic Membership Authentication

Ejemplo de como implementarlo

Crear un nuevo proyecto en Visual Studio >
File / New website /
click derecho > project / Add new Folder / [content]
click derecho > folder content / Add new web form / Default.aspx
Seleccione esta página como StartPage.
click derecho > project / Add new web form / Login.aspx

Eliminar la página Default.aspx del directorio raiz del project








Crear nuevo usuario y roles

En ASP.NET Web Site Administration Tool >
Security / Use the security Setup Wizard to configure security step by step./
[x] from the internet
[x] Enable roles for this Web site
Create New Role: [admin] Add role
user name: [usuario] [password*] [...] Create user
[x] active user
Continue NEXT>

Ahora para restringir el acceso no autorizado a los contenidos configurar los roles así



Agregar este contenido al web form Login.aspx



y se verá así



Agregar este contenido al web form Default.aspx



y se verá así

System.Diagnostics, Debug Class & Trace Class

MSDN Debug
MSDN Trace
MSDN System.Diagnostics

C# Programming Guide

MSDN C# Programming Guide

viernes, 29 de abril de 2011

Threading Tutorial

MSDN System.Threadings (MSDN Monitor Class) (MSDN ThreadPool Class) (MSDN Thread Class)
MSDN Threading Tutorial

Covariance and Contravariance in Generics


MSDN Covariance and Contravariance in Generics

Variance in Delegates


MSDN Variance in Delegates

Diferencia entre los parámetros PARAM, OUT y REF

PARAM es un argumento de parámetro de un método que toma un número variable de argumentos.

public class MyClass
{
public static void UseParams(params int[] list)
{
for (int i = 0; i < list.Length; i++)
{
Console.Write(list[i] + " ");
}
Console.WriteLine();
}

public static void UseParams2(params object[] list)
{
for (int i = 0; i < list.Length; i++)
{
Console.Write(list[i] + " ");
}
Console.WriteLine();
}

static void Main()
{
UseParams(1, 2, 3, 4);
UseParams2(1, 'a', "test");

UseParams2();

int[] myIntArray = { 5, 6, 7, 8, 9 };
UseParams(myIntArray);

object[] myObjArray = { 2, 'b', "test", "again" };
UseParams2(myObjArray);


// The following call causes a compiler error because the object
// array cannot be converted into an integer array.
//UseParams(myObjArray);

// The following call does not cause an error, but the entire
// integer array becomes the first element of the params array.
UseParams2(myIntArray);
}
}

/*
Output:
1 2 3 4
1 a test

5 6 7 8 9
2 b test again
System.Int32[]
*/

OUT y REF son parámetros de métodos que hacen referencia al parámetro pasado como argumento.

OUT no tiene valor al ser declarado como parámetro, sino que el método tiene que asignarle un valor antes de ser devuelto. En caso contrario dará error. Este argumento de parámetro es muy útil cuando se necesita un método que devuelva varios valores.

REF necesita tener valor al ser declarado como parámetro, el método, al ser invocado puede modificar o no, este valor del parámetro.

* Es un error sobrecargar métodos con la única diferencia de REF o OUT. Otro error es pasar una propiedad de la clase (como si fuera una variable) como argumento out de un método.

//valid
class MyClass
{
public void MyMethod(int i) {i = 10;}
public void MyMethod(out int i) {i = 10;}
}

public static void MyMethod(out int[] arr)
{
arr = new int[10];
}

public static void MyMethod(ref int[] arr)
{
arr = new int[10];
}

//invalid
class MyClass
{
public void MyMethod(ref int i) {i = 10;}
public void MyMethod(out int i) {i = 10;}
}



MSDN out
MSDN ref
MSDN params
MSDN Method Parameters