Problem compiling Handler.ashx

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mil111
    New Member
    • Jan 2008
    • 9

    Problem compiling Handler.ashx

    Can somebody help please. I'm trying to compile Handler (code is below), but I'm getting error message :
    ImageHandle.ash x<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!

    Code:
    <%@ 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;
            }
        }
    
    }
  • mil111
    New Member
    • Jan 2008
    • 9

    #2
    I still haven't found the solution. Does somebody know what the problem is, please?
    Thanks!!!

    Comment

    • kenobewan
      Recognized Expert Specialist
      • Dec 2006
      • 4871

      #3
      Here is a post that may help:
      Command Line Compiler, CS0116: A namespace does not directly contain members such as fields or methods

      or try:
      Compiler Error CS0116

      Originally posted by mil111
      I still haven't found the solution. Does somebody know what the problem is, please?
      Thanks!!!

      Comment

      • mil111
        New Member
        • Jan 2008
        • 9

        #4
        Thanks,
        I'll try this, maybe it will help.

        Comment

        • Dsmacks

          #5
          In Visual Studio right click and select properties on the codebehind file "myhandler.ashx .cs" onn the Build Action select Compile. Then rebuild solution and run all should be tickety-boo!

          Comment

          Working...