locked
Embedded Resource - "This is an invalid webresource request." RRS feed

  • Question

  • User-383897782 posted

    This is my first time in dealing with embedded resources, so I'm sure I'm just doing something wrong.

    I have a javascript file in my VS 2005 project file, which I've set for Build Action --> Embedded Resource.

    Then, to ensure I would name the resource correctly, I used the:

    Assembly.GetManifestResourceNames() to get the precise resource names in the file.

    One of these was "Topaz.Javascript.AjaxConn.js".

    So I added this attribute to the AssemblyInfo.cs:

    [assembly: WebResource("Topaz.Javascript.AjaxConn.js", "text/javascript")]

    And my page uses this code:

    if (Assm.GetManifestResourceInfo("Topaz.Javascript.AjaxConn.js")==null)
     throw new Exception("The resource could not be found.");

    string resource = this.ClientScript.GetWebResourceUrl(this.GetType(), "Topaz.Javascript.AjaxConn.js");
    this.ClientScript.RegisterClientScriptInclude("Topaz.Javascript.AjaxConn.js", resource);

    The page renders the include as:

    <script src="/WebResource.axd?d=VN0sC0vng-8704Qafmpaw7fc6RWl2EYakKsJpu0PSPldWOMAJ0rNrn2D0QMAovDw0&amp;t=632921217899531250" type="text/javascript"></script>

    HOWEVER, the resource is not actually found and the javascript methods are not available to me.

    If I type the url in directly:

    /WebResource.axd?d=VN0sC0vng-8704Qafmpaw7fc6RWl2EYakKsJpu0PSPldWOMAJ0rNrn2D0QMAovDw0&amp;t=632921217899531250

    I get a 404 "The resource cannot be found error".

    If I trap the application error, I get a "This is an invalid webresource request." error.

    Does anyone have some advice for what I may be doing wrong?

    Thanks,
    JK

    Friday, August 25, 2006 8:27 PM

All replies

  • User-383897782 posted

    Well, for what its worth, the problem went away when I did two things:

    1.  I moved the AssemblyInfo.cs into the "Properties" folder (probably completely insignificant, but I thought I'd mention it).

    2.  I changed the GetWebResourceUrl command.  It was pulling a type from the current page instance: this.GetType().  I changed this to read:

    string resource = this.ClientScript.GetWebResourceUrl(typeof(BasePage),"Topaz.Javascript.AjaxConn.js");

    The "BasePage" class is in the same assembly as the resource, whereas "this" refers to the inherited page that was NOT in the same assembly.  Perhaps this is necessary?

    Suddenly everything was working.

    JK

    Monday, August 28, 2006 1:49 AM
  • User-1756373192 posted
    Glad I found this post I was having the exact same issue - right down to using a class called "BasePage" in my project! This was fixed just as your previous post said. The type that is passed into the RegisterClientScriptResource method needs to be a type that is within the same assembly as the resource you are registering.  Thanks for posting your solution!
    Wednesday, August 30, 2006 12:41 AM
  • User916334707 posted

    The "BasePage" class is in the same assembly as the resource, whereas "this" refers to the inherited page that was NOT in the same assembly.  Perhaps this is necessary?

    Better use typeof(Global) where Global is the class inside Global.asax.cs which inherrits HttpApplication. This class is always inside the same assembly as AssemblyInfo.cs is applied to (where the resources are defined)
     

    Saturday, September 23, 2006 7:04 AM
  • User839295574 posted

    Hello to everybody.

     I run the same issue from 1 day. The explanation is very simple.

    When We are inside a user control, this.Page.GetType().Equals(typeof(YourNamespace.YourPageClass)) == false.

    This because when a page is run in ASP.NET, a new type wich INHERITS the YourNamespace.YourPageClass is created.

    What you must do to work 4 sure is to use this.Page.GetType().BaseType. It works

    Thursday, February 28, 2008 4:01 AM
  • User1002078793 posted

    Hey everyone, have just spent a couple of hours trying to also get this working.

    My scenario was similar to this, trying to add script resource from within a user control. My user control was in a different namespace to the comsuming webpage.

    The only way I could get this to work was by specifying "this.GetType().BaseType" as the type parameter for Page.ClientScript.GetWebResourceUrl.

    Hope this is usefull for other people experiencing the same problem.

    Cheers, Adam 

    Wednesday, September 16, 2009 7:45 AM
  • User-2004922477 posted

    Thanks to one of the earlier posters.


    I resolved my issue using 'BaseType' approach.


    thanks


    Jay

    Friday, November 20, 2009 5:11 PM