加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.NET:WebResource.axd调用404错误:如何知道哪个程序集/资源

发布时间:2020-12-15 18:50:14 所属栏目:asp.Net 来源:网络整理
导读:我在ASP.NET 3.5(AJAX)Web应用程序中的特定WebResource.axd调用上收到404 HTTP状态错误(未找到)。我猜错误被抛出,因为在bin文件夹/ GAC中缺少一个特定的被引用的程序集。但我不知道哪个,因为请求资源的页面是非常复杂的(我使用第三方控件和ASP.NET Ajax。)
我在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路径。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读