ASP.NET:WebResource.axd调用404错误:如何知道哪个程序集/资源缺失或负责?

时间:2009-01-12 12:42:33

标签: asp.net assemblies webresource.axd

我在ASP.NET 3.5(AJAX)Web应用程序中的特定WebResource.axd 调用中遇到 404 HTTP状态错误(未找到)。我猜错误是因为bin文件夹/ GAC中缺少特定的引用程序集。但我不知道哪个,因为请求资源的页面非常复杂(我使用的是第三方控件和ASP.NET Ajax。)

是否可以从查询的加密“d”查询字符串参数中获知,如:

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

哪个程序集应该创建内容并且可能会丢失?

注意:还有其他成功执行的WebRequest.axd调用。

4 个答案:

答案 0 :(得分:31)

此问题的原因之一是注册的嵌入式资源路径不正确或资源不存在。确保将资源文件添加为Embedded Resource

Asp.net使用WebResourceAttribute,您必须提供资源的路径。

需要将资源文件作为嵌入式资源添加到项目中,并且它的路径将是完整的命名空间和文件名。

所以你在项目“MyAssembly”中有以下项目资源“my.js”,资源路径将是“MyAssembly.my.js”。

要检查Web资源处理程序未找到哪个文件,您可以解密WebResource.axd网址上提供的哈希代码。请参阅下面的示例,了解如何执行此操作。

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?";
            } 
        }
    }
}

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

这应该返回aspt.net认为嵌入式资源所在的URL路径。

答案 1 :(得分:11)

我花了好几个小时处理类似的问题。由于Diadistis指出的伟大文章,我能够解密WebResource网址并发现我的WebResource被翻译成错误的程序集指针,可以通过资源名称前面的垃圾识别。经过多次努力,我发现这是因为我在一个类中使用了Page.ClientScript.GetWebResourceUrl,该类派生自另一个类,它位于我的资源所在的程序集之外。令人困惑的是,我的类在同一个程序集中是WAS,尽管源自的类是NOT。 this.GetType()参数很多文章状态是必须的,结果在我的情况下根本不是必须的。实际上,它需要替换为typeof()并且它有效!希望这可以防止其他人像我从这个bugger那样得到同样的头痛。

答案 2 :(得分:10)

在我的情况下,404错误的来源是运行IIS的计算机的日期和时间错误(从过去开始)。

答案 3 :(得分:2)

您的项目是否缺少任何参考?

是否有任何引用设置为CopyLocal = False(与Infragistics或GAC'ed refs相同)不能到达目的地?

像reactor或dependency walker这样的实用程序会告诉你主程序集是否缺少任何不明显的依赖项。

global.asax中的Application_Error处理程序是否有产生任何错误信息的catch(FileNotFoundExceptions)?

您是否将custom errors设置为“仅限远程”并从本地计算机浏览该网站?