TAILIEUCHUNG - Professional ASP.NET 3.5 in C# and Visual Basic Part 134

Professional in C# and Visual Basic Part 134. Building on the revolutionary release, adds several key new developer features including AJAX, LINQ, and a new CSS designer in Visual Web Developer 2008. The dramatic reduction in code that developers realized from the more than 50 new server controls in now allows developers the time to make their applications more interactive with AJAX, to work with data in their preferred language with LINQ, and to build visually attractive and consistent standards-based sites with CSS. . | Chapter 27 Modules and Handlers using public class Handler IHttpHandler public void ProcessRequest HttpContext context Logic to retrieve the image file image jpeg public bool IsReusable get return false As you can see you simply change the ContentType to image jpeg to indicate that you are returning a JPEG image then you use the WriteFile method to write an image file to the output stream. Load the handler into a browser and you see that the handler displays the image. Figure 27-8 shows the resulting Web page. Figure 27-8 1292 Chapter 27 Modules and Handlers Now you create a simple Web page to display the image handler. Listing 27-9 shows code for the Web page. Listing 27-9 A sample Web page using the HttpHandler for the image source DOCTYPE html PUBLIC - W3C DTD XHTML EN http TR xhtml11 DTD html xmlns http 1999 xhtml head runat server title HttpHandler Serving an Image title head body form id form1 runat server div img src div form body html Although this sample is simple you can enhance it by passing querystring parameters to your handler and using them to perform additional logic in the handler. For instance you can pass an ID in to dynamically retrieve an image from a SQL database and return it to the client like this img src imageid 123 Mapping a File Extension in IIS Although using the .ashx file extension is convenient you might want to create an HTTP handler for a custom file extension or even for a commonly used extension. Use the code from the image handler to demonstrate this. Create a new class in the App_Code directory of your Web project. You can simply copy the code from the existing image handler control into this class as shown in Listing 27-10. Notice that you removed the WebHandler directive because this is only a class and not a generic handler control. Other than that the code is the same. Listing 27-10 .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.