Thanks. As I am verifying the deployed project in the server, it is not possible to run in in debug mode. Any other advice?
Oned,
I tried this but I still see nothing from the deployed project when running it
...
<asp:Label ID="sh_addr"
width="500px"
Font-Names="Arial"
Font-Size="9pt"
ForeColor="DarkBlue"
Font-Bold="false"
runat="server" />
<EmptyDataTemplate>
No Data
</EmptyDataTemplate>
<asp:Image ID="img"
imageurl='<%# Eval("user_abbr","ImgHandler.ashx?user_abbr={0}") %>'
runat="server" />
Hi,
Oned,
I have this
...
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:BoundField />
<asp:TemplateField>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No Data
</EmptyDataTemplate>
</asp:GridView>
<br /><br />
...
but still nothing comes out
wmec
Contributor
6228 Points
3226 Posts
Nothing is shown
Nov 23, 2012 05:24 AM|LINK
Hi,
Using this part
...
public void ProcessRequest(HttpContext context)
{
System.Data.SqlClient.SqlDataReader rdr = null;
System.Data.SqlClient.SqlConnection conn = null;
System.Data.SqlClient.SqlCommand selcmd = null;
try
{
conn = new System.Data.SqlClient.SqlConnection
(System.Configuration.ConfigurationManager.ConnectionStrings
["Mssqlconn2"].ConnectionString);
string user_abbr = context.Request.QueryString["user_abbr"];
string strParameter="";
if (HttpContext.Current.Request.QueryString["user_abbr"]!=null)
{
strParameter = HttpContext.Current.Request.QueryString["user_abbr"];
}
string strQuery = "select photo_file from user_master where user_abbr='" + strParameter + "'";
selcmd = new System.Data.SqlClient.SqlCommand(strQuery, conn);
conn.Open();
rdr = selcmd.ExecuteReader();
while (rdr.Read())
{
context.Response.ContentType = "image/jpg";
context.Response.BinaryWrite((byte[])rdr["photo_file"]);
}
if (rdr != null)
rdr.Close();
}
finally
{
if (conn != null)
conn.Close();
}
}
and having this part in the markup
<asp:Image ID="img"
imageurl='<%# Eval("user_abbr","ImgHandler.ashx?user_abbr={0}") %>'
runat="server" />
when running the project, I am getting empty page there. Why?
HuaMin Chen
rtpHarry
All-Star
56620 Points
8958 Posts
Re: Nothing is shown
Nov 23, 2012 05:34 AM|LINK
Hi, I have to leave the house now but that way that you have created the SQL statement has a security hole and leaves you open to SQL Injection.
Look up using named parameters and always do this from now on!
wmec
Contributor
6228 Points
3226 Posts
Re: Nothing is shown
Nov 23, 2012 05:43 AM|LINK
How to adjust the hole? Why does nothing come out? If you need, I can send you my project.
HuaMin Chen
rtpHarry
All-Star
56620 Points
8958 Posts
Re: Nothing is shown
Nov 23, 2012 07:00 AM|LINK
Hi,
This is a good sample of using Named Parameters:
It could be several reasons why your code isn't working, for each point of failure you need to put a breakpoint on it and check it out, eg:
string user_abbr = context.Request.QueryString["user_abbr"];
Check this has a value.
while (rdr.Read())
Check this bit is actually looping and attempting to output something
context.Response.BinaryWrite((byte[])rdr["photo_file"]);
Check rdr["photo_file"] has something in it.
oned_gk
All-Star
31834 Points
6517 Posts
Re: Nothing is shown
Nov 23, 2012 07:22 AM|LINK
Add empty data template to the GV
<asp:GridView ID="GridView1" runat="server" . . . <EmptyDataTemplate> No Data </EmptyDataTemplate> </asp:GridView>If no data text displayed, the problem not from the image, but from your datasource
wmec
Contributor
6228 Points
3226 Posts
Re: Nothing is shown
Nov 23, 2012 07:33 AM|LINK
Harry,
Thanks. As I am verifying the deployed project in the server, it is not possible to run in in debug mode. Any other advice?
Oned,
I tried this but I still see nothing from the deployed project when running it
...
<asp:Label ID="sh_addr"
width="500px"
Font-Names="Arial"
Font-Size="9pt"
ForeColor="DarkBlue"
Font-Bold="false"
runat="server" />
<EmptyDataTemplate>
No Data
</EmptyDataTemplate>
<asp:Image ID="img"
imageurl='<%# Eval("user_abbr","ImgHandler.ashx?user_abbr={0}") %>'
runat="server" />
HuaMin Chen
oned_gk
All-Star
31834 Points
6517 Posts
Re: Nothing is shown
Nov 23, 2012 08:03 AM|LINK
I think wrong place empty data template
<asp:GridView ID="GridView1" runat="server"> <Columns> <asp:BoundField /> <asp:TemplateField> </asp:TemplateField> </Columns> <EmptyDataTemplate> No Data </EmptyDataTemplate> </asp:GridView>wmec
Contributor
6228 Points
3226 Posts
Re: Nothing is shown
Nov 23, 2012 08:15 AM|LINK
Hi,
Oned,
I have this
...
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:BoundField />
<asp:TemplateField>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No Data
</EmptyDataTemplate>
</asp:GridView>
<br /><br />
...
but still nothing comes out
HuaMin Chen
rtpHarry
All-Star
56620 Points
8958 Posts
Re: Nothing is shown
Nov 23, 2012 12:22 PM|LINK
What happens when you try to access the image handler directly as in:
http://www.example.com/ImgHandler.ashx?user_abbr=VALID_USER_ABBR_HERE
What is in the photo_file field? Binary jpeg data or a path to a physical file?
I dont have much experience with ado.net but is this section correct:
rdr = selcmd.ExecuteReader(); while (rdr.Read()) { context.Response.ContentType = "image/jpg"; context.Response.BinaryWrite((byte[])rdr["photo_file"]); }Its in a while loop so is this going to try to output the ContentType more than once? What does the .Read() do?
oned_gk
All-Star
31834 Points
6517 Posts
Re: Nothing is shown
Nov 23, 2012 12:35 PM|LINK