![]() |
|
|
|||||||
![]() |
ASP Net - can't display resource image from assembly |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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 |
|
|
|
#3 |
|
Posts: n/a
|
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 |
|
|
|
#4 |
|
Posts: n/a
|
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 |
|
|
|
#5 |
|
Posts: n/a
|
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 |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |