Asp.net
ASP.NET:WebResource.axd 呼叫 404 錯誤:如何知道哪個程序集/資源失去或負責?
我在 ASP.NET 3.5 (AJAX) Web 應用程序內的特定 WebResource.axd呼叫上收到404 HTTP 狀態錯誤(未找到) 。我猜這個錯誤是因為 bin 文件夾/GAC 中缺少特定的引用程序集而引發的。但我不知道是哪個,因為請求資源的頁面非常複雜(我使用的是第三方控制項和 ASP.NET Ajax。)
是否可以從查詢的加密“d”查詢字元串參數中知道,例如:
.../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(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 路徑。