ImageHandle.ashx<1,1>:error Cs0116: A namespace does not directly contain members such as fields or methods.
I can't figure out what the problem is.
Thanks!
Expand|Select|Wrap|Line Numbers
- <%@ WebHandler Language="C#" Class="ImageHandler" %>
- using System;
- using System.Web;
- using System.Web.Configuration;
- using System.Data;
- using System.Data.SqlClient;
- public class ImageHandler : IHttpHandler
- {
- public void ProcessRequest (HttpContext context)
- {
- string connString = WebConfigurationManager.ConnectionStrings["AdWorks"].ConnectionString;
- string photoId = context.Request.QueryString["PhotoId"];
- SqlConnection conn = new SqlConnection(connString);
- string sql = "SELECT ThumbnailPhoto FROM Production.ProductPhoto WHERE ProductPhotoID = @ProductPhotoID";
- SqlCommand command = new SqlCommand(sql, conn);
- command.Parameters.AddWithValue("@ProductPhotoID", photoId);
- try
- {
- conn.Open();
- SqlDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess);
- if (reader.Read())
- {
- int bufferSize = 100;
- byte[] bytes = new byte[bufferSize];
- long bytesRead;
- long readFrom = 0;
- do
- {
- bytesRead = reader.GetBytes(0, readFrom, bytes, 0, bufferSize);
- context.Response.BinaryWrite(bytes);
- readFrom += bufferSize;
- }
- while (bytesRead == bufferSize);
- }
- reader.Close();
- }
- finally
- {
- conn.Close();
- }
- }
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }