Nested dll resources

Is there pure access to embedded resources (css / js / images, etc.) inside the dll.

For example, can you use something similar to the following from an aspx page?

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

+6
source share
3 answers

I would suggest taking a look at WebResource.axd and the way to access embedded resources, for example, here:

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

you can get the server url of the resource as follows:

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

and then display it on the page

+4
source

Thanks for looking at WebResource again, but not understanding how this works. It was just a different look, and now I have a small 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 on my main 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 is located in the folder named Styles in the dll, and therefore Styles.filename.css)


Important notes:

I found that the first argument accepted by GetWebResourceUrl should be a class inside a dll project not a class inside the website being used.

I also had enormous difficulty in determining the correct name to use for the resource in the AssemblyInfo.cs file. I found that my assembly name does not match my default namespace. The default namespace should be used to form the argument 'resourceName' for GetWebResourceUrl.

+3
source

Create a resource provider. The Aspx page will check the name of the resource in the query string. then retrieves the resource from the dll, and the binary writes the resource to the output.

then name it like this:

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

Source: https://habr.com/ru/post/885713/


All Articles