Lm th? no ? t?o ra m?t ASP.L?I HTTP x? l? b?ng cch s? d?ng Visual C#.NET

D?ch tiu ? D?ch tiu ?
ID c?a bi: 308001 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

? Trang ny

Bi vi?t-by-step ny ch?ng t? lm th? no ? s? d?ng Visual C#.NET ? t?o m?t n gi?n, tu? ch?nh HTTP handler. Bi vi?t ny ch?ng t? lm th? no ? t?o, tri?n khai v ?t c?u h?nh cc x? l?.

THNG TIN THM

Th?c hi?n cc Handler

  1. Microsoft Visual Studio m?.NET. Trong Visual C#.NET, t?o ra m?t d? n l?p th vi?n m?i ?t tn l MyHandler.
  2. Thi?t l?p m?t ti li?u tham kh?o ? cc System.web.dll gan y Cynulliad.
  3. Thm ch? th? sau l?p:
    using System.Web;
    					
  4. ?i tn l?p SyncHandler.cs, v sau thay ?i ?nh ngh?a l?p ? ph?n nh i?u ny.
  5. Th?c hi?n cc IHttpHandler giao di?n. ?nh ngh?a l?p h?c c?a b?n s? xu?t hi?n nh sau:
    public class SyncHandler : IHttpHandler
    					
  6. Th?c hi?n cc IsReusable b?t ?ng s?n v cc ProcessRequest phng php c?a cc IHttpHandler giao di?n. B?i v? y l m?t b? x? l? ?ng b?, tr? v? Sai ?i v?i cc IsReusable ti s?n ? cho x? l? khng ?c g?p l?i.
    public bool IsReusable
    {
       get {return false;}
    }
    
    public void ProcessRequest(HttpContext context)
    {
       context.Response.Write("Hello from custom handler.");
    }
    					
  7. Bin d?ch d? n.

Tri?n khai vi?c x? l?

  1. T?o m?t th m?c m?i tn l Handler d?i th m?c C:\Inetpub\Wwwroot.
  2. T?o m?t th m?c con tn l rc trong th m?c b? x? l? m?i ?c thnh l?p. ?ng d?n k?t qu? l C:\Inetpub\Wwwroot\Handler\Bin.
  3. Sao chp MyHandler.dll c?a d? n Bin\Debug th m?c vo th m?c C:\Inetpub\Wwwroot\Handler\Bin.
  4. Th?c hi?n theo cc b?c sau ? nh d?u cc th m?c Handler m?i nh l m?t ?ng d?ng Web:
    1. M? b? qu?n l? d?ch v? Internet.
    2. Nh?p chu?t ph?i vo th m?c Handler v b?m Thu?c tnh.
    3. Trn cc Th muc tab, b?m vo Tao.
  5. Th?c hi?n theo cc b?c sau ? t?o ra m?t ?ng d?ng l?p b?n ? cho b? x? l?. ?i x? l? ny, t?o ra m?t b?n ? ? cc t?p tin Aspnet_isapi.dll cho ph?n m? r?ng *.sync. B?t c? khi no m?t t?p tin .sync ?c yu c?u, yu c?u ?c ?nh tuy?n ?n ASP.NET, v ASP.NET th?c hi?n m? trong x? l?.
    1. Nh?p chu?t ph?i vo cc ?ng d?ng x? l? Web v b?m Thu?c tnh.
    2. Trn cc Th muc tab, b?m vo Cu hinh.
    3. Nh?p vo Thm ? thm m?t b?n ? m?i.
    4. Trong cc Tr?nh th?c hi?n vn b?n h?p, g? ?ng d?n sau y: Microsoft Windows 2000:
      C:\WINNT\Microsoft.NET\Framework\<version#>\Aspnet_isapi.dll </version#>
      Microsoft Windows XP:
      C:\WINDOWS\Microsoft.NET\Framework\<version#>\Aspnet_isapi.dll </version#>
    5. Trong cc Ph?n m? r?ng h?p vn b?n, lo?i .Sync.
    6. H?y ch?c ch?n r?ng cc Ki?m tra r?ng t?p tin t?n t?i h?p ki?m tra s? b? xa, v b?m Ok ? ng nh?ng Thm/ch?nh s?a Ti?n ch m? r?ng ?ng d?ng b?n ? h?p tho?i.
    7. Nh?p vo Ok ? ng nh?ng C?u h?nh ?ng d?ng v cc Thu?c tnh x? l? h?p tho?i.
  6. ng b? qu?n l? d?ch v? Internet.

C?u h?nh h? th?ng

  1. Trong th m?c C:\Inetpub\Wwwroot\Handler, t?o m?t t?p tin m?i tn Web.config.
  2. Thm m? sau vo Web.config:
    <configuration>
       <system.web>
          <httpHandlers>
             <add verb="*" path="*.sync" type="MyHandler.SyncHandler, MyHandler" />
          </httpHandlers>
       </system.web>
    </configuration>
    						
    Trong cc ?ng t? = "*" thu?c tnh, chng ti h?ng d?n x? l? ? x? l? m?t yu c?u c s? d?ng b?t c? danh t? (v d?, bi, ?u, GET, v do trn). N?u b?n mu?n ny x? l? ? x? l? ch? yu c?u bi, thay ?i ny ? ?ng t? = "ng bi".

    Trong cc ?ng d?n = "*.sync" thu?c tnh, chng ti h?ng d?n x? l? ? x? l? cc yu c?u ?n t?p tin v?i ph?n m? r?ng .sync.

    Trong cc type="MyHandler.SyncHandler (MyHandler)" thu?c tnh, chng ti h?ng d?n x? l? cc quy tr?nh theo yu c?u ? th?c hi?n trong cc MyHandler.SyncHandler khng gian tn, v l?p ny c tr trong cc MyHandler gan y Cynulliad.

Ki?m tra cc m-un

? ki?m tra m?t handler, m?t trang khng c?n ? t?n t?i trong h? th?ng t?p tin. V d?, yu c?u cc t?p tin Default.sync trong ?ng d?ng Handler Web (http://<computername>/Handler/Default.sync). B?n s? nh?n ?c cc k?t qu? sau: </computername>
Hello from custom handler.
				

THAM KH?O

? bi?t thm chi ti?t v? x? l? HTTP, b?m vo s? bi vi?t d?i y ? xem bi vi?t trong c s? ki?n th?c Microsoft:
307985 THNG TIN: ASP.NET HTTP m-un v HTTP x? l? t?ng quan

Thu?c tnh

ID c?a bi: 308001 - L?n xem xt sau cng: 27 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft ASP.NET 1.1
  • Microsoft ASP.NET 1.0
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
T? kha:
kbconfig kbhowtomaster kbhttphandlers kbhttpruntime kbweb kbmt KB308001 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:308001

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com