Marked a javascript file as "Embedded resource"
Added WebResource attribute to my AssemblyInfo class
Now i'm trying to output the embedded javascript to my master page. All I'm getting is a "Web Resource not found" from the web resource url.
Project Assembly Name:
CompanyProduct
Project Default Namespace:
Company.Product.Web
Javascript file located:
Library/navigation.js
AssemblyInfo:
[assembly: WebResource("CompanyProduct.Library.navigation.js", "text/javascript")]
Code in master page:
Page.ClientScript.RegisterClientScriptInclude("NavigationScript", Page.ClientScript.GetWebResourceUrl(this.GetType(), "CompanyProduct.Library.navigation.js"));
Instead of this.GetType()
, get a type from the assembly that contains the resource.. ie:
typeof(Company.Product.Web.Library.Class1)
Does that work?
Came to the same issue today. The problem seems to be that AssemblyResourceLoader uses the assembly containing the type provided to GetWebResourceUrl
method (first parameter) which in your case is a dynamically created assembly for the master page (.master) and does not contain the resource you are looking for. I assume that your resource file is included in the same assembly as your base master page (.master.cs file) then you could use typeof
to get the Type instance
Page.ClientScript.RegisterClientScriptInclude(
"NavigationScript",
Page.ClientScript.GetWebResourceUrl(
typeof(MyMasterPage),
"CompanyProduct.Library.navigation.js"));
where MyMasterPage is the name of your master page
Looks like it is also possible to use any other type declared in the same assembly where the resource is embedded.
I think you want the full paths to be based on the namespace, not the assembly; So anywhere you have "CompanyProduct.Library.navigation.js", replace it with "Company.Product.Web.Library.navigation.js". Also, there is a method Page.ClientScript.RegisterClientScriptResource() that does what you need in one method (as opposed to using RegisterClientScriptInclude(GetWebResourceUrl()).
This is clutching at straws a bit, but could it be that your asp.net isn't set up to process the webresource.axd correctly? If something has gone wrong maybe the handler tag is missing from the machine's web.config?
The http handlers tag of C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config should have a webresource.axd entry like this:
<httpHandlers>
<add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True"/>
</httpHandlers>
Also double check there isn't any handler entry in the project's web.config that could be overriding the setting from the machine's web.config.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With