30 oct 2007

Video Curse: Creating an N-Layer ASP.NET Application


Creating an N-Layer ASP.NET Application
Description
In this video tutorial I walk through the fundamentals of creating an N-Layer ASP.NET application. What is "N-Layer" you ask? N-Layer can be interpreted many different ways, but I generally use the term to mean separating presentation, business and data code into individual code layers. Doing this allows code to be re-used throughout an application and prevents unnecessary clutter in ASP.NET code-behind classes. This video covers creating presentation, business and data layers and also covers another layer I normally add to projects that I refer to as "Model". The model layer contains data entity classes that are used to pass data between the different layers. Other types of architectures can certainly be applied as well.

Requirements .NET 2.0
View Video Click Here
Download Code:

Click Here

 

 
 
 
 

27 oct 2007

Custom Error Pages - IHttpModule

ASP.NET Resources - ASP.NET Custom Error Pages


 using System; using System.Web;  namespace AspNetResources.CustomErrors4 {   public class MyErrorModule : IHttpModule   {     public void Init (HttpApplication app)     {       app.Error += new System.EventHandler (OnError);     }      public void OnError (object obj, EventArgs args)     {       // At this point we have information about the error       HttpContext ctx =  HttpContext.Current;        Exception exception = ctx.Server.GetLastError ();        string errorInfo =              "
Offending URL: " + ctx.Request.Url.ToString () + "
Source: " + exception.Source + "
Message: " + exception.Message + "
Stack trace: " + exception.StackTrace; ctx.Response.Write (errorInfo); // -------------------------------------------------- // To let the page finish running we clear the error // -------------------------------------------------- ctx.Server.ClearError (); } public void Dispose () {} } }
 

To plug our HttpModule into the pipeline we need to add a few lines to web.config:

<?xml version="1.0" encoding="utf-8" ?> <configuration>  <system.web>   <httpModules>    <add type="AspNetResources.CustomErrors4.MyErrorModule,«                                                     CustomErrors4"      name="MyErrorModule" />   </httpModules>  </system.web> </configuration> 

event + delegate Visual C# 2.0

 

Definir eventos en Visual C# (siempre usando delegados)

El delegado lo definimos de la siguiente forma:

  public  delegate  void MiEventoEventHandler(  string param1,  int param2);

Y el evento lo definimos del tipo del delegado:

  public event MiEventoEventHandler MiEvento; 
 
Ligar un método de evento en C#
 public static void UsarMiClase1()
{
    MiClase1 prueba = new MiClase1();
    // En C# 2.0 o superior no es necesario usar el delegado
    // para ligar el método con el evento
    prueba.MiEvento += prueba_MiEvento;

    prueba.Mostrar("el Guille", 49);
}

static private void prueba_MiEvento(string param1, int param2)
{
    Console.WriteLine(
        "Se produce el evento MiEvento con los parámetros: {0} y {1}" , param1, param2);
}
  
   http://www.elguille.info/NET/dotnet/equivalenciavbcs4.htm

unsafe keyword + Using Pointers in C#

Using Pointers in C#

Now it is time to write some program code to demonstrate the use of pointers. Consider the following code.

static void Main(string[] args)
{
    int age = 32;
    Console.WriteLine("age = {0}" , age);
}

unsafe keyword

static void Main(string[] args)
{
    unsafe
    {
        int age = 32;
        int* age_ptr;

        Console .WriteLine("age = {0}", age);

    }
}

 

Pointers to Structures:

unsafe static void Main(string[] args)

{

    Location loc;

    loc.X = 100;

    loc.Y = 100;

 

    Location* loc_ptr;

    loc_ptr = &loc;

    Console.WriteLine("X = {0}", loc_ptr->X);

 

    loc_ptr->X = 200;

    Console.WriteLine("X = {0}", loc_ptr->X);

}

 

Pointers and Classes:

For Example:

 

class PTest

{

     public PTest()

     {

     }

     public int age;

     public void DisplayAge()

     {

         Console.WriteLine("age = {0}", age);

    }

}

And some example code to create an instance of the class and then manipulate the public variable age using a pointer.

unsafe static void Main(string[] args)
{
    PTest p = new PTest();

    p.age = 32;
    p.DisplayAge();

    fixed (int* age = &p.age)
    {
        *age += 3;
    }

    p.DisplayAge();
}

 

INDEXER[] in C#


INDEXER IN C#:

 

In c# introduce new concept is Indexer. This is very useful for some situation. Let as discuss something about Indexer.

  • Indexer Concept is object act as an array.

  • Indexer an object to be indexed in the same way as an array.

  • Indexer modifier can be private, public, protected or internal.

  • The return type can be any valid C# types.

  • Indexers in C# must have at least one parameter. Else the compiler will generate a compilation error.

this [Parameter]

{

    get

    {

        // Get codes goes here

    }

    set

    {

        // Set codes goes here

    }

}  

 

For Example:

 

using System;

using System.Collections.Generic ;

using System.Text ;

 

namespace Indexers

{

    class ParentClass

    {

        private string[] range = new string[5];

        public string this[ int indexrange]

        {

            get

            {

                return range[indexrange];

            }

            set

            {

                range[indexrange] = value;

            }

        }

    }

 

    /* The Above Class just act as array declaration using this pointer */

 

    class childclass

    {

        public static void Main()

        {

            ParentClass obj = new ParentClass();

 

            /* The Above Class ParentClass   create one object name is obj */

 

            obj[0] = "ONE";

            obj[1] = "TWO";

            obj[2] = "THREE";

            obj[3] = "FOUR ";

            obj[4] = "FIVE";

            Console.WriteLine( "WELCOME TO C# CORNER HOME PAGE\n");

            Console.WriteLine( "\n");

 

            Console.WriteLine( "{0}\n,{1}\n,{2}\n,{3}\n,{4}\n", obj[0], obj[1], obj[2], obj[3], obj[4]);

            Console.WriteLine( "\n");

            Console.WriteLine( "ALS.Senthur Ganesh Ram Kumar\n");

            Console.WriteLine( "\n");

             Console.ReadLine();

        }

    }

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

http://www.c-sharpcorner.com/UploadFile/senthurganesh/109172007050741AM/1.aspx

 

 

 

 

 

 

 

 

 

 

 

FeedCount

analytics

 
sfrede