javascript - Embedded dll resources - Stack Overflow

Is there a clean way of accessing embedded resources (cssjsimages etc) inside a dll.For example, from

Is there a clean way of accessing embedded resources (css/js/images etc) inside a dll.

For example, from an aspx page, can something similar to the below be used?

<script type="text/javascript" src="<%= ResolveUrl("~/My.Dll.Namespace.File.js") %>"></script>

Is there a clean way of accessing embedded resources (css/js/images etc) inside a dll.

For example, from an aspx page, can something similar to the below be used?

<script type="text/javascript" src="<%= ResolveUrl("~/My.Dll.Namespace.File.js") %>"></script>

Share Improve this question asked Apr 12, 2011 at 9:45 Red TazRed Taz 4,1994 gold badges43 silver badges61 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

I would suggest to take a look at WebResource.axd and the way how you can access embedded resources, like for example here:

http://weblogs.asp/jeff/archive/2005/07/18/419842.aspx

you can get the resource url on server side like this:

Page.ClientScript.GetWebResourceUrl(typeof(MyNameSpaces.MyControl), "MyNameSpaces.Resources.MyImage.gif")

and then render it on page

Thanks I had a look at WebResource a while back but didn't fully understand how it worked. Just had another look & I've now got a tidy little solution.

For those interested, I have a class in my dll called Resource with a static method as follows

public static string Get(Page p, string file) {
    return p.ClientScript.GetWebResourceUrl(typeof(Resource), typeof(Resource).Namespace + ".Resources." + file);
}

After using the register directive in my master page (or web.config) I can now do the following

<link href="<%= Resource.Get(this.Page, "Styles.reset.css") %>" rel="stylesheet" type="text/css" />

(reset.css resides within a folder called Styles in the dll, hence Styles.filename.css)


Important Notes:

I discovered that the first argument accepted by GetWebResourceUrl must be of a class within the dll project not a class within consuming website.

I also had tremendous difficulty determining the correct fully qualified name to use for the resource in the AssemblyInfo.cs file. I discovered that my assembly name was not the same as my default namespace. The default namespace should be used to form the 'resourceName' argument for GetWebResourceUrl.

Create a Resource Provider Aspx Page witch will check for a resource name in query string. then retrieves resource from dll and binary writes the resource in output.

then call it like this :

<script type="text/javascript" 
    src="ResourceProvider.aspx?name=My.Dll.Namespace.File.js"></script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745076874a4609886.html

相关推荐

  • javascript - Embedded dll resources - Stack Overflow

    Is there a clean way of accessing embedded resources (cssjsimages etc) inside a dll.For example, from

    18小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信