ASP.Net中的Web Resource
http://support.microsoft.com/kb/910442,这是中文的,机器翻译的,不太容易看懂,英文的是:http://support.microsoft.com/kb/910442/en-us。
记录几个要点:
- Web Resource是什么?解决什么问题?Web Resource使用一种称为WebResouce.axd的处理程序(Hanlder),该处理程序用来从Assembly中检索抽取(retrieve)静态资源文件并返回给浏览器。处理程序WebResource.axd的类型是AssemblyResourceLoader。
- Web Resource是怎样解决这些问题的(Web Resource是如何工作的How Web Resource Work)?也就是Web Resource是怎样根据请求从Assembly中检索抽取静态文件并返回给客户端的(分解开来,这里有两个个问题(1)针对WebResouce.axd的请求时如何产生的;(2)处理程序WebResource.axd处理该请求的具体过程是怎样的)?针对前面的问题(2)(问题(1)的答案见下面的第4点),回答如下:When a request comes in from the client for WebResource.axd, the handler looks for the Web Resource identifier in theQueryString method of the Request object(当一个针对WebResource.axd的请求从客户端进来时,WebResource.axd处理程序从该请求的QueryString方法中查找Web Resource identifier). Based on the value of the Web Resource identifier, the handler then tries to load the assembly that contains this resource(然后,WebResource.axd试图加载包含Web Resource identifier所指资源的Assembly). If this operation is successful, the handler will then look for the assembly attribute and load the resource stream from the assembly. Finally, the handler will grab the data from the resource stream and send it to the client together with the content type that you specify in the assembly attribute。The URL for WebResource.axd looks like the following:
WebResource.axd?d=SbXSD3uTnhYsK4gMD8fL84_mHPC5jJ7lfdnr1_WtsftZiUOZ6IXYG8QCXW86UizF0&t=632768953157700078
The format of this URL is WebResource.axd?d=encrypted identifier&t=time stamp value. The "d" stands for the requested Web Resource. The "t" is the timestamp for the requested assembly, which can help in determining if there have been any changes to the resource.
- 如何将静态资源文件嵌入Assembly?
- 如何从Assembly中取出静态资源文件(即如何生成对处理程序WebResource.axd的请求)?For getting the Web Resource, I have used the GetWebResourceUrl method, which is a method of the ClientScriptManagerclass that is typically used for managing client-side scripts. This method returns a URL reference to the server-side resource that is embedded in an assembly. The GetWebResourceUrl method accepts the following two parameters:
- Type: The type of the server-side resource
- Resource Name: The name of the server-side resource
To use this method, first you have to create an instance of the ClientScriptManager class and get the type of the class as shown below.When you have an instance of this class, you then have to call this method and pass the appropriate parameters as shown below, where I create a HyperLink button, and set the NavigateURL method to point to an embedded HTML resource.
HyperLink hlHelpFile = new HyperLink();
hlHelpFile.NavigateUrl = cs.GetWebResourceUrl(rsType, "SimpleControl.Help.htm");
hlHelpFile.Attributes.Add("onmouseover", "ChangeImage('image1','Red')");
hlHelpFile.Attributes.Add("onmouseout", "RollbackImage('image1','Green')"); this.Controls.Add(hlHelpFile); Image imgTest = new Image();
imgTest.ImageUrl = cs.GetWebResourceUrl(rsType, "SimpleControl.smallFail.gif");
imgTest.ID = "image1";
hlHelpFile.Controls.Add(imgTest);回到上面1的问题,Web Resouce解决什么问题?解决的是为客户端返回资源文件的问题,所以如果你知道了资源文件的位置(也就是说如果你请求的资源文件不再Assembly中),完全没有必要使用Web Resource。
ASP.Net中的Web Resource的更多相关文章
- Asp.net中的web.config配置
目录 Asp.net中的web.config配置... 1 一. 配置文件保存位置... 2 二. 配置文件加载顺序... 2 三. 配置文件节点介绍... 3 1. . 3 2. . 5 3. . ...
- 请解释ASP. NET中的web页面与隐藏类之间的关系
请解释ASP.NET中的web页面与其隐藏类之间的关系 其实页面与其隐藏类之间就是一个部分类的关系,你在页面上放一个一个的控件就是在这个类中定义一个一个的属性, 因为是同一个类的部分类的关系,所以隐藏 ...
- Asp.net中的web.config配置文件(转)
最近开始学习.NET的开发,首先碰到的就是web.config的配置问题,把网上大虾的资料转发记录一下,以备不时之需. 原贴路径如下:http://blog.csdn.net/hbqhdlc/arti ...
- 请解释ASP.NET 中的web 页面与其隐藏类之间的关系?
一个ASP.NET 页面一般都对应一个隐藏类,一般都在ASP.NET 页面的声明中指定了隐藏类例如一个页面 Tst1.aspx 的页面声明如下 <%@ Page language="c ...
- 请解释ASP.NET中的web页面与其隐藏类之间的关系
其实页面与其隐藏类之间就是一个部分类的关系,你在页面上放一个一个的控件就是在这个类中定义一个一个的属性, 因为是同一个类的部分类的关系,所以隐藏类可以访问到页面上控件,这样做是为了把展现与处理逻辑分开 ...
- 关于Idea模块化部署web项目,Web Resource Directories作用
问题由来:接到某个所谓“将web工程中部分代码抽出打包,但待打包部分代码还需要在现场部署时能做微调”的需求. 解决方法:将待打包部分代码作为一个module,让工程依赖该模块,满足抽离打包与现场可调试 ...
- ASP.NET 5系列教程 (六): 在 MVC6 中创建 Web API
ASP.NET 5.0 的主要目标之一是统一MVC 和 Web API 框架应用. 接下来几篇文章中您会了解以下内容: ASP.NET MVC 6 中创建简单的web API. 如何从空的项目模板中启 ...
- ASP.NET MVC4中调用WEB API的四个方法
http://tech.it168.com/a2012/0606/1357/000001357231_all.shtml [IT168技术]当今的软件开发中,设计软件的服务并将其通过网络对外发布,让各 ...
- 返璞归真 asp.net mvc (11) - asp.net mvc 4.0 新特性之自宿主 Web API, 在 WebForm 中提供 Web API, 通过 Web API 上传文件, .net 4.5 带来的更方便的异步操作
原文:返璞归真 asp.net mvc (11) - asp.net mvc 4.0 新特性之自宿主 Web API, 在 WebForm 中提供 Web API, 通过 Web API 上传文件, ...
随机推荐
- Linux第02天
Linux 第02天 1.Linux磁盘和文件系统 VFS————虚拟文件系统 df命令————查看已挂载的分区 df 分区名 du命令————查看文件夹大小 du 文件夹名 ln命令————符号链接 ...
- VMware下虚拟机的转移
将虚拟机文件夹整个拷贝到另一台电脑上: 打开.vmx文件 打开即可: 注意:Mac系统的虚拟机要先用unlocker206破解,才能运行OS系统.
- Java代码常用写法总结
1.字符串是否为空判断 以下是java 判断字符串是否为空的四种方法:方法一: 最多人使用的一个方法, 直观, 方便, 但效率很低: if(s == null ||"".equal ...
- activity 、window与view的关系 (上)
我在研究任玉刚老师的<android开发艺术探索>的关于windowmanager那一章时,我发现自己对于acitivity.window和view之间的概念还是比较模糊. 然后查了一下a ...
- 【Unity3d游戏开发】unity3D OnTriggerEnter和OnCollisionEnter的一点个人心得(转载)
此文为转载,因为最近在做U3D,有一些概念弄得不是很清楚,看到这篇博客讲的不错,就转载过来了,方便自己随时查看. ------------------------------------------- ...
- jquery cookie的用法
http://www.cnblogs.com/qiantuwuliang/archive/2009/07/19/1526663.html jQuery cookie是个很好的cookie插件,大概的使 ...
- Jquery和其他库($的好处)
---很多时候我们的页面 会使用很多的 javascript库 ---而这个时候 jQuery这款重点在满足社区用户的需求的工具 做好了让jQuery在页面上与其他库和平共处的准备 凭借名副其实的 ...
- sql server存储过程中SELECT 与 SET 对变量赋值的区别
SQL Server 中对已经定义的变量赋值的方式用两种,分别是 SET 和 SELECT. 对于这两种方式的区别,SQL Server 联机丛书中已经有详细的说明,但很多时候我们 并没有注意,其实这 ...
- Java图片转换为base64格式
/** * @Descriptionmap 将图片文件转化为字节数组字符串,并对其进行Base64编码处理 * @author temdy * @Date 2015-01-26 * @param pa ...
- Canvas里绘制矩阵文字
效果如下 实现方法: [ [0,0,1,1,1,0,0], [0,1,1,0,1,1,0], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [1,1,0,0,0,1,1], [1 ...