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, 05: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, 10: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


  Reply With Quote
Old 09-17-2006, 03: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
>



  Reply With Quote
Old 09-17-2006, 11:19 AM   #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.


  Reply With Quote
Old 09-17-2006, 06: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.
>
>



  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
Forum Jump