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

发布于 2024-07-11 19:54:22 字数 381 浏览 4 评论 0原文

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

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

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

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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

澜川若宁 2024-07-18 19:54:23

如果存在检测到查询字符串中指定字符串的请求过滤规则,也会出现同样的问题。 在我的例子中,AXD 文件的查询字符串是使用规则检测到的双破折号生成的,并导致 AXD 文件请求出现 404 未找到错误。

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.

暗地喜欢 2024-07-18 19:54:22

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

Asp.net 使用 WebResourceAttribute 您必须给出资源的路径。

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

因此,您在项目“MyAssembly”中有以下项目资源“my.js”,资源路径将为“MyAssembly.my.js”。

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

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 的原始代码示例链接: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

这应该返回 URL 路径aspt.net 认为嵌入式资源位于。

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.

榆西 2024-07-18 19:54:22

我刚刚在类似的问题上花了几个小时。 由于 Diadistis 指出的这篇精彩文章,我能够解密 WebResource url,并发现我的 WebResource 被转换为错误的程序集指针,可以通过资源名称前面的垃圾来识别。 经过多次斗争,我发现这是因为我在派生自另一个类的类中使用 Page.ClientScript.GetWebResourceUrl,而该类位于我的资源所在的程序集之外。令人困惑的是,我的类位于同一个程序集中派生的类不是。 许多文章都指出 this.GetType() 参数是必须的,但事实证明在我的情况下根本不是必须的。 实际上,它需要用 typeof() 替换,并且它起作用了! 希望这可以防止其他人像我一样从这个混蛋那里得到同样的头痛。

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.

帅哥哥的热头脑 2024-07-18 19:54:22

就我而言,404 错误的根源是运行 IIS 的计算机的日期和时间错误(来自过去)。

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).

乖乖兔^ω^ 2024-07-18 19:54:22

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

是否有任何设置为 CopyLocal=False 的引用(常见于 Infragistics 或 GAC'ed 引用)但无法到达目的地?

像反射器或依赖项遍历器这样的实用程序会告诉您主程序集是否缺少任何不立即明显的依赖项。

global.asax 中的 Application_Error 处理程序是否有一个正在产生的捕获任何错误信息(FileNotFoundExceptions)?

您是否将自定义错误设置为“仅限远程”并浏览该网站从本地机器?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文