ASP.Net中的Web Resource

时间:2023-01-09 08:57:03

http://support.microsoft.com/kb/910442,这是中文的,机器翻译的,不太容易看懂,英文的是:http://support.microsoft.com/kb/910442/en-us。

记录几个要点:

  1. Web Resource是什么?解决什么问题?Web Resource使用一种称为WebResouce.axd的处理程序(Hanlder),该处理程序用来从Assembly中检索抽取(retrieve)静态资源文件并返回给浏览器。处理程序WebResource.axd的类型是AssemblyResourceLoader。
  2. 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.

  3. 如何将静态资源文件嵌入Assembly?
  4. 如何从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的更多相关文章

  1. Asp.net中的web.config配置

    目录 Asp.net中的web.config配置... 1 一. 配置文件保存位置... 2 二. 配置文件加载顺序... 2 三. 配置文件节点介绍... 3 1. . 3 2. . 5 3. . ...

  2. 请解释ASP. NET中的web页面与隐藏类之间的关系

    请解释ASP.NET中的web页面与其隐藏类之间的关系 其实页面与其隐藏类之间就是一个部分类的关系,你在页面上放一个一个的控件就是在这个类中定义一个一个的属性, 因为是同一个类的部分类的关系,所以隐藏 ...

  3. Asp.net中的web.config配置文件(转)

    最近开始学习.NET的开发,首先碰到的就是web.config的配置问题,把网上大虾的资料转发记录一下,以备不时之需. 原贴路径如下:http://blog.csdn.net/hbqhdlc/arti ...

  4. 请解释ASP.NET 中的web 页面与其隐藏类之间的关系?

    一个ASP.NET 页面一般都对应一个隐藏类,一般都在ASP.NET 页面的声明中指定了隐藏类例如一个页面 Tst1.aspx 的页面声明如下 <%@ Page language="c ...

  5. 请解释ASP&period;NET中的web页面与其隐藏类之间的关系

    其实页面与其隐藏类之间就是一个部分类的关系,你在页面上放一个一个的控件就是在这个类中定义一个一个的属性, 因为是同一个类的部分类的关系,所以隐藏类可以访问到页面上控件,这样做是为了把展现与处理逻辑分开 ...

  6. 关于Idea模块化部署web项目,Web Resource Directories作用

    问题由来:接到某个所谓“将web工程中部分代码抽出打包,但待打包部分代码还需要在现场部署时能做微调”的需求. 解决方法:将待打包部分代码作为一个module,让工程依赖该模块,满足抽离打包与现场可调试 ...

  7. ASP&period;NET 5系列教程 &lpar;六&rpar;&colon; 在 MVC6 中创建 Web API

    ASP.NET 5.0 的主要目标之一是统一MVC 和 Web API 框架应用. 接下来几篇文章中您会了解以下内容: ASP.NET MVC 6 中创建简单的web API. 如何从空的项目模板中启 ...

  8. ASP&period;NET MVC4中调用WEB API的四个方法

    http://tech.it168.com/a2012/0606/1357/000001357231_all.shtml [IT168技术]当今的软件开发中,设计软件的服务并将其通过网络对外发布,让各 ...

  9. 返璞归真 asp&period;net mvc &lpar;11&rpar; - asp&period;net mvc 4&period;0 新特性之自宿主 Web API&comma; 在 WebForm 中提供 Web API&comma; 通过 Web API 上传文件&comma; &period;net 4&period;5 带来的更方便的异步操作

    原文:返璞归真 asp.net mvc (11) - asp.net mvc 4.0 新特性之自宿主 Web API, 在 WebForm 中提供 Web API, 通过 Web API 上传文件, ...

随机推荐

  1. Error&colon;Execution failed for task &&num;39&semi;&colon;clean&&num;39&semi;&period; &gt&semi; Unable to delete directory :&bsol;build&bsol;intermediates (转)

    第一种方法: build文件夹,可以使用360文件粉碎机删除,然后重启Android Studio即可! 转自 第二种方法: 进入studio,进入settings,搜索instant run,进入该 ...

  2. Oracle定时查询结果输出到指定的log文件

    最近有个监控项目需要采集数据库信息,原来方案是写个sql脚本,每个脚本放一个查询语句然后通过操作系统层su到oracle用户通过sqlpus执行这个.sql,然后加到crontab定时执行.但是这个问 ...

  3. 点击checkbox,触发事件

    时间选择: 起始时间:<input type="text" value="2016-03-21 12:24:10" id="starttime& ...

  4. C&num;按需序列化对象为Json字符串

    只贴代码,不解释了.新的代理类型确实很给力! public static class JsonHelper { public static string ToJsonString<T>(I ...

  5. WEB项目web&period;xml文件中classpath&colon; 跟classpath&ast;&colon;使用的区别

    引用一篇很不错的文章:http://blog.csdn.net/wxwzy738/article/details/16983935 首先 classpath是指 WEB-INF文件夹下的classes ...

  6. Java-螺旋方阵

    用Java实现螺旋方阵 螺旋方阵:是指呈螺旋状的矩阵. 具体实现如下: public void screwMatrix() { System.out.print("请输入数字:") ...

  7. linux shell中的 &num;&excl;&sol;bin&sol;bash

    #!/bin/bash是指此脚本使用/bin/bash来解释执行. 其中,#!是一个特殊的表示符,其后,跟着解释此脚本的shell路径. bash只是shell的一种,还有很多其它shell,如:sh ...

  8. java--面向对象编程

    instanceof的用法 静态绑定,即早期绑定,首先找父类 动态绑定,即运行时绑定,new谁找谁 Object o1 = null; //正确的语法,null也是一种特殊的引用数据类型 object ...

  9. 基于JS的WEB会议室预订拖拽式图形界面的实现

    06年的一篇blog,转到这个博客上: 很早之前写的,后来由于这个功能模块取消,最终没有上线,所以与Server交互的那部分还没有写,不过那部分方案我也已经出来了,而且现在客户端这一部分已经通过了比较 ...

  10. CSS如何把一张横向的长图变成竖向的?

    前言: 有时候做项目过程中,设计的是一张横向的长图,但是我们需要在手机端观看的时候,也想把手机横着观看,这样视野更宽阔,如何解决这个问题呢? html <div class="imgB ...