Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - can't display resource image from assembly

 
Thread Tools Search this Thread
Old 09-16-2006, 06:22 PM   #1
Default 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 ????




Jon Paal
  Reply With Quote
Old 09-16-2006, 11:34 PM   #2
Alex
 
Posts: n/a
Default Re: can't display resource image from assembly
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




Alex
  Reply With Quote
Old 09-17-2006, 04:18 AM   #3
Jon Paal
 
Posts: n/a
Default Re: can't display resource image from assembly
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" <for-groups-> wrote in message news:...
> 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
>





Jon Paal
  Reply With Quote
Old 09-17-2006, 12:19 PM   #4
Alex
 
Posts: n/a
Default Re: can't display resource image from assembly
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.




Alex
  Reply With Quote
Old 09-17-2006, 07:20 PM   #5
Jon Paal
 
Posts: n/a
Default Re: can't display resource image from assembly
thanks again it is now working, seems my earlier problems with app_code were namespace related.


"Alex" <for-groups-> wrote in message news:...
> 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.
>
>





Jon Paal
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
HDDVD/Bluray: stillborn or coma Rexunrex@yahoo.com DVD Video 586 01-31-2007 07:05 PM
Image acquires Criterion Goro DVD Video 2 08-04-2005 02:28 AM
Anamorphic downconversion, digital video essentials, my recent foray into videophile land, frustration and heartbreak cg DVD Video 18 09-21-2004 01:30 AM
Advantage of 4:3 hdtv over old 4:3 Adam Smith DVD Video 17 12-15-2003 07:25 PM
New Releases: Short Circuit, Kung Fu Series, Image Horror: Updated complete downloadbable R1 DVD DB & info lists Doug MacLean DVD Video 0 12-13-2003 05:31 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46