使用整个WebResource.axd的嵌入式WebResources [英] Using embedded WebResources throughout Webresource.axd

查看:237
本文介绍了使用整个WebResource.axd的嵌入式WebResources的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题的简单:在asp.net应用何以采用嵌入式资源?什么是包括在组件中的资源的步骤,以及如何引用它?什么是可能遇到的陷阱?

The question's simple: how could one use embedded resources in asp.net applications? What are the steps to include a resource in the assembly, and how to reference it? What are the gotchas that could be encountered?

推荐答案

花了一天半后,我已经学会了这些:

After spending a half of a day I've learned these:


  1. 要嵌入一个需要设置它是一种资源的生成操作嵌入的资源(适用于VS解决方案资源管理器中单击鼠标右键将文件 - >属性)

  1. to embed a resource one needs to set it's Build Action to Embedded Resource (in VS Solution Explorer rightclick the file -> Properties)

接下来的 AsssemblyInfo.vb 必须进行修改,以供查询WebResource这个资源。添加 [大会:System.Web.UI.WebResource(MyWebResourceProj.Test.css,文/ CSS)] 来AssemblyInfo.vb中位于的文件夹MyProject的项目。

next AsssemblyInfo.vb must be modified to make this resources available for WebResource queries. Add [Assembly: System.Web.UI.WebResource("MyWebResourceProj.Test.css", "text/css")] to AssemblyInfo.vb located in MyProject folder of the project.


  • 名称由根命名空间/集名称+的'。'+文件名。为了100%肯定的名称,请使用以下code段来关注一下吧:结果
    昏暗resNames = Assembly.LoadFile(YourDll.dll)。GetManifestResourceNames()

  • 需要注意的是,大会的根命名空间必须是相同的程序集名称(这个我花了大约4个小时来实现,至少与.net V4是这种情况)

  • 如果还有的CSS里面引用(小于(%)= WebResource(NS.image.jpg)%>),比通过PerformSubstitution:= TRUE对于CSS的WebResource属性

  • The name consists of root namespace/assembly name +'.'+filename. To be 100% sure of the name, use the following code snippet to look it up:
    Dim resNames = Assembly.LoadFile("YourDll.dll").GetManifestResourceNames()
  • Note that the assembly's Root Namespace must be the same as the Assembly Name (this took me about 4 hours to realize. At least with .Net v4 that is the case)
  • If there are references inside the css ( <%=WebResource("NS.image.jpg")%> ) than pass PerformSubstitution:=true for that css's WebResource attribute.

引用可与 Page.ClientScript.GetWebResourceUrl来完成资源(的GetType(MyWebResourceProj.ConssumingPage),MyWebResourceProj.Test.css)


  • 请注意,不是的GetType(类型名)人们可以使用Me.GetType(),但同样,这是行不通的,如果这个类是继承,所以要小心!

资源:

  • Debugging ASP.NET 2.0 Web Resources: Decrypting the URL and Getting the Resource Name

这篇关于使用整个WebResource.axd的嵌入式WebResources的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆