ASP.NET: WebResource.axd call 404 error: how to know which assembly/resource is missing or responsible?

29,172

Solution 1

One of the reasons for this issue is that the registered embedded resource path is incorrect or the resource is not there. Make sure the resource file is added as a Embedded Resource.

Asp.net uses the WebResourceAttribute which you must give the path to the resource.

The resource file needs to be added as a Embedded Resource to the project and the path to it would be the full namespace plus the file name.

So you have the following project resource "my.js" in the project "MyAssembly" the resource path would be "MyAssembly.my.js".

To check what file the web resource handler is not finding you can decrypt the hash code provided on the WebResource.axd url. Please see the example below an how to do that.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            byte[] encryptedData = HttpServerUtility.UrlTokenDecode("encoded hash value");

            Type machineKeySection = typeof(System.Web.Configuration.MachineKeySection);
            Type[] paramTypes = new Type[] { typeof(bool), typeof(byte[]), typeof(byte[]), typeof(int), typeof(int) };
            MethodInfo encryptOrDecryptData = machineKeySection.GetMethod("EncryptOrDecryptData", BindingFlags.Static | BindingFlags.NonPublic, null, paramTypes, null);

            try
            {
                byte[] decryptedData = (byte[])encryptOrDecryptData.Invoke(null, new object[] { false, encryptedData, null, 0, encryptedData.Length });
                string decrypted = System.Text.Encoding.UTF8.GetString(decryptedData);

                decryptedLabel.Text = decrypted;
            }
            catch (TargetInvocationException)
            {
                decryptedLabel.Text = "Error decrypting data. Are you running your page on the same server and inside the same application as the web resource URL that was generated?";
            } 
        }
    }
}

Original code example by Telerik UI for ASP.NET AJAX Team Link: http://blogs.telerik.com/aspnet-ajax/posts/07-03-27/debugging-asp-net-2-0-web-resources-decrypting-the-url-and-getting-the-resource-name.aspx

This should return the URL path that aspt.net believes the embedded resource is at.

Solution 2

In my case, the source of the 404 error was that the date and time of the machine running IIS were wrong (from the past).

Solution 3

I just spent hours on a similar issue. Due to the great article pointed out by Diadistis I was able to decrypt the WebResource url and find out that my WebResource was translated into a wrong assembly pointer, recognizable by the garbage in front of your resource name. After many struggles I found out that this was because I was using the Page.ClientScript.GetWebResourceUrl in a class deriving from another class which resided outside of the assembly my resource was in. Confusing thing was that my class WAS in the same assembly, though the class deriving from was NOT. The this.GetType() parameter many articles state is a must, turned out not to be so much of a must at all in my situation. Actually, it needed to be replaced with a typeof() and it worked! Hope this may prevent others from getting the same headache as I got from this bugger.

Solution 4

Is your project missing any references?

Are there any references set to CopyLocal=False (common with Infragistics or GAC'ed refs) that dont make it to the destination?

A utility like reflector or dependency walker will tell you if your main assembly is missing any dependencies that are not immediately obvious.

Does the Application_Error handler in global.asax have a catch that is producing any error info (FileNotFoundExceptions)?

Did you set custom errors to 'remote only' and browse the site from the local machine?

Solution 5

This same issue occurs if there is a request filtering rule that detects the specified string in the query string. In my case, the query string for the AXD file was generated with a double dash that the rule detected and caused a 404 not found error for the AXD file request.

Share:
29,172

Related videos on Youtube

splattne
Author by

splattne

My first computer (1983) was a Commodore VIC-20. I love my wife, my two kids & my job as developer. I'm a PC, but I own some Macs and iStuff too.

Updated on July 09, 2022

Comments

  • splattne
    splattne almost 2 years

    I get a 404 HTTP status error (not found) on a specific WebResource.axd call inside an ASP.NET 3.5 (AJAX) web application. I guess the error is thrown because a specific referenced assembly is missing in the bin folder/GAC. But I don't know which, since the page which requests the resource is very complex (I'm using third-party controls and ASP.NET Ajax.)

    Is it possible to know from the encrypted "d" querystring parameter of the query, like:

    .../WebResource.axd?d=...
    

    which assembly should create the content and is possibly missing?

    Note: There are other WebRequest.axd calls which execute with success.

    • Mr. Flibble
      Mr. Flibble over 10 years
      If everything worked fine and then suddenly it broke after a server restart, then check your server clock is set correctly.
    • fnostro
      fnostro about 10 years
      @Mr.Flibble: This was it exactly for me. We had a power outage on our development servers that caused our time servers to restart with the wrong time, and all servers connected to that time server, including our IIS server, likewise were set to the same incorrect time when power was restored. This caused the problem mentioned by the OP. I learned something today...it's a good day
  • NightOwl888
    NightOwl888 over 12 years
    The link is broken. I found it at the following url in a Google search: blogs.telerik.com/blogs/posts/07-03-26/…
  • Jason Kleban
    Jason Kleban about 12 years
    typeof() vs this.GetType() made the difference for me. Excellent.
  • Jonathan van de Veen
    Jonathan van de Veen about 10 years
    @Diadistis The link seems broken to me.
  • Jay Sullivan
    Jay Sullivan over 9 years
    I'm confused...my link is http://example.com/ScriptResource.axd?d=...&t=...; do I put just the "d" part in there? Or the entire URL? (It fails either way.)