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

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

是否可以从查询的加密的“d”querystring参数知道,如:

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

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

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

解决方法

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

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(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,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为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路径。

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....