Home
Links
Home Page
HTML_AJAX In operation
The guidebook on an exchange of links
Bases of creation of server elements of management. Events
Postback and Query String - to combine incompatible
Kategorial`noe ordering of results of search
We change URL'? hurriedly
XML+MSSQL+ASP.NET. A part 1.
As work Web services ASP.NET
New in ASP.NET 2. Structures of users
Transformation of a target stream of the XML-given at a conclusion in a browser means ASP.NET and XS
Expectation of performance of long process in ASP.NET
Difference between HttpModule and HttpHandler
New in asp.net 2 - subjects and skiny.
Review GridView
What is GridView
Role of a content in promotion of a site
Review DetailsView
Job with databases
AutoPostBack Binding to the data. Collections. Check of correctness of the entered data


Difference between HttpModule and HttpHandler

HttpModule - global obrabotchik searches to all pages of the application with which help it is possible "to put" in various stages of processing of search (not life cycle of page, namely search). For example, if necessary to carry out installation of some parameters (for example lokali) is possible to create HttpModule, containing obrabotchik events Begin_Request.



public void Init (HttpApplication context)

{

   // We add obrabotchiki

   context. BeginRequest + = new EventHandler (context_BeginRequest);  

}


void context_BeginRequest (object sender, EventArgs e)

{

  // Certain operations

}


Or, for example, if it is necessary at search on autentifikaciju the user to receive the information on the user it is necessary to create obrabotchik AuthenticateRequest.


In general, with help IHttpModule and context (which HttpApplication) it is possible "to be hung up" on the following events: AuthorizeRequest, AuthenticateRequest, BeginRequest, EndRequest, Error and many others about which it is possible to read in MSDN.


Important feature HttpModule is that in execution time of the application there is only one copy of a class of each module. The some people umel`cy manage at initialization of the module in Init to load the data and to store{keep} in object of the module, using it{him} as some analogue Application. Personally I do not recommend the similar approach.


About HttpModules it is possible to read in George Sheferda's HTTP Modules clause{article}.


HttpHandler - obrabotchik concrete search. As against HttpModule, copies HttpHandler are created (or turn out from a pool of objects) for each search. It is possible even to name, probably, HttpHandler "zaproso-specific" as the object is created under each search and works with the data specific to concrete search. It is necessary to note, that any ASP.NET page javzjaetsja HttpHandler.


Good example of use HttpHandler is creation obrabotchika "giving out" a picture or XML files from a database. For this purpose it is enough to adhere obrabotchik to the certain expansion in web.config a file:



<httpHandlers>

  <add verb = "*" path = "*.rss " type = " dotRssCenter. RssHandler "/>

</httpHandlers>


And in method ProcessRequest corresponding obrabotchika to obtain the data from a database and to return to the user. Such method use of rewriting URL and usual aspx pages as in case of use HttpHandler there is no life cycle of page and an overhead charge connected to his{its} processing will be significant more proizvoditelen, than.


By the way, a quite good example of use HttpHandler is my module for rewriting URL.


That upon termination of performance of search, the copy of class HttpHandler was not destroyed, and passed in a pool of objects, it is necessary in property IsReusable to return true:



public bool IsReusable

{

  get {return true;}

}


Though, at speed of creation of objects by modern machines not yet understandably, whether there will be time for restoration from a pool and a premise{room} in a pool buol`she.


More in detail about creation HttpHandler it is possible to read in a management{manual} in MSDN.


I hope, that I have clearly enough explained a difference between HttpModule and HttpHandler. If you still had questions, favour ask to leave them in comments to this message.



\\\\\\\\\\\\\\\\\\\\\\\







Expectation of performance of long process in ASP.NET

We admit{allow}, we have page Default.aspx on which the user enters a name of the client and number{room} of the waybill then there is a check of this number{room}. As check can borrow{occupy} long time it is necessary to provide the user with the information on a course of performance of process (goes or has already passed). The simplest way is resulted below.


Default



using System;

using System. Data;

using System. Configuration;

using System. Collections;

using System. Web;

using System. Web. Security;

using System. Web. UI;

using System. Web. UI.WebControls;

using System. Web. UI.WebControls. WebParts;

using System. Web. UI.HtmlControls;

using System. Threading;


public partial class _Default: System. Web. UI.Page

{


    protected Guid _id;


    protected void Page_Load (object sender, EventArgs e)

    {

        if (Page. IsPostBack)

        {

            _id = Guid. NewGuid ();


            ThreadStart ts = new ThreadStart (Check);

            Thread th = new Thread (ts);

            th. Start ();


            Response. Redirect (" Invoice.aspx? ID = " + _id. ToString ());

}

}


    protected void Check ()

    {

        string res = InvoiceProcessor. CheckInvoice (txtName. Text, txtNumber. Text);

        CheckedInvoices. Add (_id, res);

}


}


Essence in that the unique identifier is created. On which the result will be received from the khehsh-table of results. An example of a class of table CheckedInvoices and a class - zaglushki which in the normal application carries out check InvoiceProcessor, are resulted below.


CheckedInvoices



using System;

using System. Collections;


public static class CheckedInvoices

{

    private static Hashtable _invoices = new Hashtable ();


    public static string GetResult (Guid id)

    {

        if (_invoices. Contains (id))

        {

            return Convert. ToString (_invoices [id]);

}

        else

        {

            return " ";

}

}


    public static void Add (Guid id, string value)

    {

        _invoices [id] = value;

}


    public static void Remove (Guid id)

    {

        _invoices. Remove (id);

}

}


InvoiceProcessor



using System;

using System. Threading;


public static class InvoiceProcessor

{

    public static string CheckInvoice (string customerName, string invoiceID)

    {

        Thread. Sleep (10000);

        if (invoiceID == "qwerty")

        {

            return " the Current status: it is transferred{handed} to service dostavkinOzhidaemoe time of delivery: the devil only knows ";

}

        else if (invoiceID == "asdfgh")

        {

            return " the Current status: dostavlenonOzhidaemoe time of delivery: so already ";

}

        else

        {

            return " there Is no information under the given waybill ";

}

}

}


The page on which readdressing is carried out, should check readiness of result only.


Invoice



using System;

using System. Data;

using System. Configuration;

using System. Collections;

using System. Web;

using System. Web. Security;

using System. Web. UI;

using System. Web. UI.WebControls;

using System. Web. UI.WebControls. WebParts;

using System. Web. UI.HtmlControls;


public partial class Invoice: System. Web. UI.Page

{

    protected void Page_Load (object sender, EventArgs e)

    {

        if (Request. Params ["ID"]! = null)

        {

            Guid id = new Guid (Request. Params ["ID"]);


            if (CheckedInvoices. GetResult (id) .Length == 0)

            {

                phInvoice. Controls. Add (new LiteralControl (" Please, wait... "));

                Response. AddHeader ("Refresh", "5");

}

            else

            {

                phInvoice. Controls. Add (new LiteralControl (CheckedInvoices. GetResult (id)));

                CheckedInvoices. Remove (id);

}

}

        else

        {

            phInvoice. Controls. Add (new LiteralControl (" the identifier of the waybill is not specified. "));

}

}

}


The circuit is very simple - on page Default.aspx occurs postbehk, during this moment the new unique identifier which is passed a method, vypolnjaemumo in separate process is created. After that there is a readdressing on page Invoice.aspx where there is a check on identifikutoru (peredanomu in GET search) in table CheckedInvoices, whether there are no there data. If the data no, the heading, informing is sent a browser about necessity to make Refresh if the result has appeared to the user the result is deduced, and a key udaljaesja from the khehsh-table as it is not necessary any more.