此问题的原因之一是注册的嵌入式资源路径不正确或资源不存在。确保将资源文件添加为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(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 的 ASP.NET AJAX 团队链接的原始代码示例:http: //blogs.telerik.com/aspnet-ajax/posts/07-03-27/debugging-asp-net-2-0-web-resources-解密-the-url-and-getting-the-resource-name.aspx
这应该返回 aspt.net 认为嵌入资源所在的 URL 路径。