Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reasons why WebResources cannot be found

Hi I am having trouble getting an embedded js file to work.

I have tried all of the following:

  • Running Cassini development server (VS2008, .NET 3.5)
  • Added [assembly: WebResource("MyNamespace.MyScriptFile.js", "text/javascript")] above the class's namespace declaration.
  • Script file has build action "Embedded Resource".
  • Tried registering during OnInit, OnLoad and OnPreRender
  • Script file is in the same assembly and namespace as the control registering it.
  • Opened assembly with Reflector and verified the name of the resource is correct.
  • Does not work using any of the following methods:

    ScriptManager.RegisterClientScriptResource(Page, GetType(), "MyNamespace.MyScriptFile.js");
    
    Page.ClientScript.RegisterClientScriptResource(GetType(), "MyNamespace.MyScriptFile.js");
    
    Page.ClientScript.RegisterClientScriptInclude(GetType(), "key",
        Page.ClientScript.GetWebResourceUrl(GetType(), "MyNamespace.MyScriptFile.js"));
    
    • Other WebResource.axd files are being found - only this one is not being found.

The request for the resource returns a 404 page with an exception listed: "*[HttpException]: This is an invalid webresource request.*"

Using the ScriptManager.RegisterClientScriptResource produces the exception:

"*Web resource 'MyNamespace.MyScriptFile.js' was not found.*"
like image 531
cbp Avatar asked Jun 18 '26 16:06

cbp


1 Answers

In your example code, you are making a call to GetType()... the type is used as the starting point for the search. Depending on where you are making your call to GetType(), you may not be getting back what you expect. Since ASP.NET dynamically compiles types for your pages and custom controls, GetType() may be returning a type defined in a new assembly built by ASP.NET.

You could try doing typeof(SomeType) instead, where SomeType is appropriate based on the location of your resource (ex. the control type you're working with).

like image 80
Michael Petito Avatar answered Jun 25 '26 10:06

Michael Petito



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!