Asynchronous handlers in asp.net
-
Upload
abhishek-sur -
Category
Technology
-
view
2.167 -
download
2
description
Transcript of Asynchronous handlers in asp.net
![Page 1: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/1.jpg)
Asynchronous Handlers in ASP.NET
KolkataGeeks 1
![Page 2: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/2.jpg)
HTTP Handlers
• An ASP.NET HTTP handler is a process, which runs in response to a request made to an ASP.NET web application.
Handler Description
.aspx Default handler for all ASP.NET Web Pages
.asmx Default handler for all Web Service Pages
.ashx Default handler for all Web Handlers, that have no UI, instead have @WebHandler directive
KolkataGeeks 2
![Page 3: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/3.jpg)
Hierarchy
IHttpHandler interfacevoid ProcessRequest(HttpContext ctx); bool IsReusable {get;}
IHttpAsyncHandler : IHttpHandler IAsyncResult BeginProcessRequest(HttpContext ctx, AsyncCallback cb, object obj); void EndProcessRequest(IAsyncResult ar);
Implemented By Synchronous Handler Implemented By Asynchronous Handler
KolkataGeeks 3
![Page 4: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/4.jpg)
Synchronous Handler
• A synchronous handler returns only after complete processing of the HTTP request, for which it is called.
KolkataGeeks 4
![Page 5: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/5.jpg)
Synchronous Handler
CLIENT
THREAD POOL
R1
T1
REQUEST QUEUE
ERROR 503
KolkataGeeks 5
![Page 6: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/6.jpg)
KolkataGeeks 6
![Page 7: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/7.jpg)
KolkataGeeks 7
![Page 8: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/8.jpg)
KolkataGeeks 8
![Page 9: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/9.jpg)
Registering Http Handler in Web.Config file
KolkataGeeks 9
![Page 10: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/10.jpg)
KolkataGeeks 10
![Page 11: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/11.jpg)
Asynchronous Handlers
• Asynchronous programming helps in better usage of resources.
• In ASP.Net when a request is made, a thread is created and allocated to the handler file. the thread will be idle when the file will undergo i/o processing.
• So to properly use the thread's idle time , we can release the thread back to thread pool after passing the execution to handler file.
• When the I/O operation is complete, the framework reassigns a thread to the request and the handler can render the output to the browser.
KolkataGeeks 11
![Page 12: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/12.jpg)
Asynchronous HandlerCLIENT
BEGIN
THREAD POOL
END
I/O PROCESS
Thread 1
Thread 2
Thread 1 Released
KolkataGeeks 12
![Page 13: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/13.jpg)
IAsyncResult
• An asynchronous HTTP Handler uses an IAsyncResult object to notify when the operation has been completed.
• Once the I/O or DB operation is completed, thread is reassigned, ASP.NET will continue the execution of the handler.
KolkataGeeks 13
![Page 14: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/14.jpg)
IsReusable Property
• If the handler returns static content, it is safe to be reusable. But if the handler returns dynamic content, to make it thread safe, IsReusable property should be set as false.
• In such case, context switching may occur, which may cause the handler to give wrong output.
KolkataGeeks 14
![Page 15: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/15.jpg)
• The verb=”*” attribute, we instruct the handler to process a request that uses any verb(for eg. POST,HEAD,GET, and so on.)
• In the path=“*.sync” attribute, we instruct the handler to process any incoming requests for files with the .sync extension.
• Type=“handler class name”
KolkataGeeks 15
![Page 16: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/16.jpg)
HTTPContext
• Encapsulates all HTTP-specific information about an individual HTTP request.
KolkataGeeks 16
![Page 17: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/17.jpg)
KolkataGeeks 17
![Page 18: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/18.jpg)
KolkataGeeks 18
![Page 19: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/19.jpg)
KolkataGeeks 19
![Page 20: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/20.jpg)
Register Http Handler in Web.Config File
KolkataGeeks 20
![Page 21: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/21.jpg)
KolkataGeeks 21
![Page 22: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/22.jpg)
If registration of Handler is not done in Web.Config File
KolkataGeeks 22
![Page 23: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/23.jpg)
Now Handler is registered for *.jpg in Web.Config File
KolkataGeeks 23
![Page 24: Asynchronous handlers in asp.net](https://reader035.fdocuments.in/reader035/viewer/2022062312/554ebcb4b4c9053c4b8b46f1/html5/thumbnails/24.jpg)
KolkataGeeks 24