Thông tin tài liệu:
Using the SqlDataSource ControlLISTING 9.29 DynamicImage.ashxusing using using using usingSystem.Data; System.Web; System.Web.Configuration; System.Web.UI; System.Web.UI.WebControls;/// /// Displays an image corresponding to the Id passed /// in a query string field /// public class DynamicImage : IHttpHandler { public void ProcessRequest (HttpContext context) { // Get the Id of the image to display string imageId = context.Request.QueryString[“Id”]; // Use SqlDataSource to grab image bytes SqlDataSource src = new SqlDataSource(); src.ConnectionString = WebConfigurationManager.ConnectionStrings[“Images”].ConnectionString; src.SelectCommand = “SELECT Image FROM Images WHERE Id=” + imageId; // Return a DataView DataView view = (DataView)src.Select(DataSourceSelectArguments.Empty); context.Response.BinaryWrite( (byte[])view[0][“Image”]); // Return a DataReader...
Nội dung trích xuất từ tài liệu:
ASP.NET 4 Unleased - p 47