using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
[assembly: WebResource("DesignWebResource.Resource.img.gif","image/gif")]
namespace DesignWebResource
{
class SimpleWebResource
{
public SimpleWebResource()
{ }
private string ImageUrl;
}
}
以上是我放图片的代码。我也把图片的属性变成了”嵌入资源“
以下是使用上面的web资源网站的源码:
前台:
<asp:Image ID="Image1" runat="server" />
后台
namespace WebResourceText
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Page.ClientScript.GetWebResourceUrl(typeof(_Default), "DesignWebResource.Resource.img.jpg"));
Image1.ImageUrl = Page.ClientScript.GetWebResourceUrl(typeof(_Default), "DesignWebResource.Resource.img.jpg");
//Page.ClientScript.RegisterClientScriptResource(typeof(_Default), "DesignWebResource.Resource.img.jpg");
}
}
}
可是不知道为什么我的图片就是不出来。但是能够Response.Write出web资源的地址
我的web.config的处理程序节点为:
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True" />
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
可能是Image1.ImageUrl = Page.ClientScript.GetWebResourceUrl(typeof(_Default), "DesignWebResource.Resource.img.jpg");这句话有问题