Abraham Olatubosun

Abraham Olatubosun

  • NA
  • 471
  • 114.7k

Image Not show on Cloud Page But shows on my Machine

May 10 2017 1:41 AM
Dear Code Masters,
Good day to you all, I have a web page that have a textbox and a button for searching student record.
if the student id is entered in the textbox and the button is clicked the c# code behind search and displayed the record if found. The database structure is shown below :
 
once we search the record "cis/001" i expect the name, RegNo and the image to displayed on my development machine it worked fine, but after deploying both the database and the files to the cloud it is not working.
i have tried using this code:
  1. Image1.ImageUrl = "ImageHandler.ashx?id=" + "CIS/001"
    1. DT = ConnectAll.GetTableID(id);  
    2.        foreach (DataRow r in DT.Rows)  
    3.        {  
    4.            Byte[] bytes = (Byte[])r["picture"];  
    5.            string Base64String = Convert.ToBase64String(bytes, 0, bytes.Length);  
    6.            Image1.ImageUrl = "data:image/png;base64," + Base64String;  
    7.      }  
    ;  
the imageHandler page is a GenericHandler which have the following code:
  1. public void ProcessRequest (HttpContext context) {  
  2.         //context.Response.ContentType = "text/plain";  
  3.         //context.Response.Write("Hello World");  
  4.         try  
  5.         {  
  6.             string id = context.Request.QueryString["id"].ToString();  
  7.             using (SqlConnection cn = new SqlConnection(ConnectAll.ConnectMe()))  
  8.             {  
  9.                 cn.Open();  
  10.                 string SQL = "Select * from tbl_studReg where id ="+id;  
  11.                 SqlCommand cmd = new SqlCommand(SQL, cn);  
  12.                 //cmd.CommandType = CommandType.Text;  
  13.                 //cmd.Parameters.AddWithValue("@id", id.ToString());  
  14.                 SqlDataReader r = cmd.ExecuteReader();  
  15.                 while (r.Read())  
  16.                 {  
  17.                     context.Response.BinaryWrite((byte[])r["picture"]);  
  18.                 }  
  19.             }  
  20.         }  
  21.         catch (Exception ex)  
  22.         {  
  23.   
  24.         }  
  25.     }  
these didn't work, i also tried the following code too 
  1. DT = ConnectAll.GetTableID(id);  
  2.        foreach (DataRow r in DT.Rows)  
  3.        {  
  4.           Byte[] bytes = (Byte[])r["picture"];  
  5.           string Base64String = Convert.ToBase64String(bytes, 0, bytes.Length);  
  6.           Image1.ImageUrl = "data:image/png;base64," + Base64String;  
  7.       }  
above i have a class that return a datatable (DT)
all these did wor either but on my machine both method work fine displaying the image and the other records. Please can anyone help me?
 
thank you all 
 

Answers (4)