468,247 Members | 1,276 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,247 developers. It's quick & easy.

can't display resource image from assembly


sample code which is failing to display the image

rootnamespace.........

myproject

Assembly code................
<Assembly: WebResource("Logo.gif", "image/gif")>

code ...............
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Web
Imports System.Web.UI
Imports Microsoft.VisualBasic
NameSpace namespace1

Class class1
Inherits System.Web.UI.Page
Implements IHttpHandler

Public Function showimg() As String

Dim Response As HttpResponse = HttpContext.Current.Response
Dim returnValue As String = String.Empty

returnValue = Page.ClientScript.GetWebResourceUrl(Me.GetType(), "Logo.gif")
response.write( "<img src=""" & returnValue & """>")

End Function

End Class
End Namespace
viewsource output for image is ...................

<img src="/WebResource.axd?d=whMLBJ8IDJGvV_odhtKmwHKuto9Ppv4U 7VgziTrNxAtrvyWBq8_A4mRnZzRjVosI0&t=63293579222000 0000">

but it does not display in the web page.
by using reflector I can see the image is stored in the DLL as a resource and is correctly named
What am I missing ????
Sep 16 '06 #1
4 1571
Hi, Jon

Every thing seems to be fine. I have similar code that is working... May be
you'll find it usefull.

= = = = = = = = = = = = = = = = = = = =
HandlerTest.cs
= = = = = = = = = = = = = = = = = = = =
using System.Web;
using System.Web.UI;
using System.Web.Configuration;
using System;

[assembly: WebResource("img2.gif", "image/gif")]
namespace HandlerExample
{
public class MyHttpHandler : System.Web.UI.Page, IHttpHandler
{
// Override the ProcessRequest method.
public void ProcessRequest(HttpContext context)
{
String img2 = String.Format("<img src={0}>",
Page.ClientScript.GetWebResourceUrl(this.GetType() ,
"img2.gif"));

context.Response.Write(img2);
}
// Override the IsReusable property.
public bool IsReusable
{
get { return true; }
}
}
}

= = = = = = = = = =
Command line
= = = = = = = = = =
csc /t:library /out:../Bin/HandlerTest.dll /r:System.Web.dll
/res:img2.gif,img2.gif HandlerTest.cs
= = = = = = = = = =
Web.Config registration
= = = = = = = = = =
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="handler.aspx"
type="HandlerExample.MyHttpHandler,HandlerTest"/>
</httpHandlers>
</system.web>
</configuration>
Regards,
Alex
Sep 16 '06 #2
thanks!

I got the image to appear, but it did require 2 changes to match your coding;

1] the .vb file had to be compiled into the dll to work, can't be in the app_code folder
2] the httphandlers had to be in the web.config file.
Is there a way to have the httphandlers added programatically to the web.config file ?

"Alex" <fo*************@yandex.ruwrote in message news:ub**************@TK2MSFTNGP06.phx.gbl...
Hi, Jon

Every thing seems to be fine. I have similar code that is working... May be you'll find it usefull.

= = = = = = = = = = = = = = = = = = = =
HandlerTest.cs
= = = = = = = = = = = = = = = = = = = =
using System.Web;
using System.Web.UI;
using System.Web.Configuration;
using System;

[assembly: WebResource("img2.gif", "image/gif")]
namespace HandlerExample
{
public class MyHttpHandler : System.Web.UI.Page, IHttpHandler
{
// Override the ProcessRequest method.
public void ProcessRequest(HttpContext context)
{
String img2 = String.Format("<img src={0}>",
Page.ClientScript.GetWebResourceUrl(this.GetType() ,
"img2.gif"));

context.Response.Write(img2);
}
// Override the IsReusable property.
public bool IsReusable
{
get { return true; }
}
}
}

= = = = = = = = = =
Command line
= = = = = = = = = =
csc /t:library /out:../Bin/HandlerTest.dll /r:System.Web.dll /res:img2.gif,img2.gif HandlerTest.cs
= = = = = = = = = =
Web.Config registration
= = = = = = = = = =
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="handler.aspx" type="HandlerExample.MyHttpHandler,HandlerTest"/>
</httpHandlers>
</system.web>
</configuration>
Regards,
Alex

Sep 17 '06 #3
Hi, Jon
I got the image to appear, but it did require 2 changes to match your
coding;
1] the .vb file had to be compiled into the dll to work, can't be in the
app_code folder
Have no idea how to solve issue with App_Code, but may be such approach can
be usefull for you:
1) Compile your images into a .dll with SomeClass.
2) Then use that SomeClass from the code inside App_Code.

= = = = = = = = = = = = = = = = = = = =
HandlerTestRes.cs
= = = = = = = = = = = = = = = = = = = =
using System.Web.UI;

[assembly: WebResource("img1.gif", "image/gif")]
namespace HandlerExample
{
public class SomeClass
{
}
}

= = = = = = = = = =
Command line
= = = = = = = = = =
csc /t:library /out:../Bin/HandlerTestRes.dll /res:img1.gif,img1.gif
HandlerTestRes.cs

= = = = = = = = = = = = = = = = = = = =
SomePage.aspx.cs
= = = = = = = = = = = = = = = = = = = =
using System;
using System.Web;

public partial class SomePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String img1 = String.Format("<img src={0}>",
Page.ClientScript.GetWebResourceUrl(typeof(Handler Example.SomeClass),
"img1.gif"));

Response.Write(img1);
}
}

2] the httphandlers had to be in the web.config file.
Are you writing the HttpHandler, or just an ASPX page? If ASPX (and you code
located in corresponding .aspx.vb file) then you don't need the httphandlers
section in web.config.
Is there a way to have the httphandlers added programatically to the
web.config file ?
Don't think so.

Regards,
Alex.
Sep 17 '06 #4
thanks again it is now working, seems my earlier problems with app_code were namespace related.
"Alex" <fo*************@yandex.ruwrote in message news:O1**************@TK2MSFTNGP05.phx.gbl...
Hi, Jon
>I got the image to appear, but it did require 2 changes to match your coding;
1] the .vb file had to be compiled into the dll to work, can't be in the app_code folder

Have no idea how to solve issue with App_Code, but may be such approach can be usefull for you:
1) Compile your images into a .dll with SomeClass.
2) Then use that SomeClass from the code inside App_Code.

= = = = = = = = = = = = = = = = = = = =
HandlerTestRes.cs
= = = = = = = = = = = = = = = = = = = =
using System.Web.UI;

[assembly: WebResource("img1.gif", "image/gif")]
namespace HandlerExample
{
public class SomeClass
{
}
}

= = = = = = = = = =
Command line
= = = = = = = = = =
csc /t:library /out:../Bin/HandlerTestRes.dll /res:img1.gif,img1.gif HandlerTestRes.cs

= = = = = = = = = = = = = = = = = = = =
SomePage.aspx.cs
= = = = = = = = = = = = = = = = = = = =
using System;
using System.Web;

public partial class SomePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String img1 = String.Format("<img src={0}>",
Page.ClientScript.GetWebResourceUrl(typeof(Handler Example.SomeClass),
"img1.gif"));

Response.Write(img1);
}
}

>2] the httphandlers had to be in the web.config file.

Are you writing the HttpHandler, or just an ASPX page? If ASPX (and you code located in corresponding .aspx.vb file) then you
don't need the httphandlers section in web.config.
>Is there a way to have the httphandlers added programatically to the web.config file ?
Don't think so.

Regards,
Alex.


Sep 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Jon Davis | last post: by
reply views Thread by MikeY | last post: by
12 posts views Thread by bj7lewis | last post: by
6 posts views Thread by Saya | last post: by
reply views Thread by Jon Paal | last post: by
7 posts views Thread by craig | last post: by
10 posts views Thread by Alain R. | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.