ASP.NET 4 Unleased - p 151

Working with the HTTP Runtime { const string connectionStringName = “Images”; public void ProcessRequest(HttpContext context) { // Don’t buffer response = false; // Get file name string fileName = (); // Get image from database string conString = [connectionStringName].ConnectionString; SqlConnection con = new SqlConnection(conString); SqlCommand cmd = new SqlCommand(“SELECT Image FROM Images WHERE FileName=@FileName”, con); (“@fileName”, fileName); using (con) { (); SqlDataReader reader = (); if (()) { int bufferSize = 8040; byte[] chunk = new byte[bufferSize]; long retCount; long startIndex = 0; retCount = (0, startIndex, chunk, 0, bufferSize); while (retCount == bufferSize) { (chunk); startIndex +=. | 1474 CHAPTER 31 Working with the HTTP Runtime const string connectionStringName Images public void ProcessRequest HttpContext context Don t buffer response false Get file name string fileName Get image from database string constring connectionStringName .ConnectionString SqlConnection con new SqlConnection conString SqlCommand cmd new SqlCommand SELECT Image FROM Images WHERE FileName @FileName con @fileName fileName using con SqlDataReader reader if int bufferSize 8040 byte chunk new byte bufferSize long retCount long startindex 0 retCount 0 startindex chunk 0 bufferSize while retCount bufferSize chunk startindex bufferSize retCount 0 startindex chunk 0 bufferSize byte actualChunk new Byte retCount - 1 chunk 0 actualChunk 0 int retCount - 1 actualChunk From the Library of Wow eBook Creating HTTP Handlers 1475 public bool IsReusable get return true 31 After you create a class that implements the IHttpHandler interface you need to register the class in the web configuration file. The web configuration file in Listing includes an httpHandlers section that associates the .gif .jpeg and .jpg extensions with the Image handler. LISTING xml version configuration connectionStrings add name Images connectionString Data Source . SQLExpress Integrated Security True AttachDBFileName DataDirectory User Instance True connectionStrings httpHandlers add path .gif verb type validate false add path .jpeg verb type validate false add path .jpg verb type validate false httpHandlers configuration When you register a .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
272    388    1    26-06-2024
6    400    2    26-06-2024
Đã 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.