奇怪的ASP.NET AJAX Bug/32位到64位

Jas*_*ley 5 64-bit asp.net-ajax

自升级到Windows 2008 64位以来,我的网站出现了一个奇怪的错误.我的大多数应用程序池都以64位模式运行(除了一个之外,所有应用程序池都用于传统的ASP.NET 1.1应用程序).在64位运行的站点上,我一直在从ASP.NET AJAX中收到错误.

Exception information:
   Exception type: System.NotSupportedException
   Exception message: Assembly "AjaxControlToolkit, Version=3.0.20820.16598, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" does not contain a script with hash code "e2e86ef9".

Request information:
   Request URL: http://site.com/page.aspx?_TSM_HiddenField_=ctl00_ctl00_elScripto_HiddenField&_TSM_CombinedScripts_=%3B%3BAjaxControlToolkit%2C+Version%3D3.0.20820.16598%2C+Culture%3Dneutral%2C+PublicKeyToken%3D28f01b0e84b6d53e%3Afr-FR%3A707835dd-fa4b-41d1-89e7-6df5d518ffb5%3Ae2e86ef9%3A9ea3f0e2%3A9e8e87e9%3A1df13a87%3Ad7738de7

Thread information:
   Thread ID: 21
   Thread account name: NT AUTHORITY\NETWORK SERVICE
   Is impersonating: False
   Stack trace:    at AjaxControlToolkit.ToolkitScriptManager.DeserializeScriptEntries(String serializedScriptEntries, Boolean loaded) in c:\AjaxControlToolkit_Admin\Release\AjaxControlToolkit\ToolkitScriptManager\ToolkitScriptManager.cs:line 534
  at AjaxControlToolkit.ToolkitScriptManager.OutputCombinedScriptFile(HttpContext context) in c:\AjaxControlToolkit_Admin\Release\AjaxControlToolkit\ToolkitScriptManager\ToolkitScriptManager.cs:line 264
  at AjaxControlToolkit.ToolkitScriptManager.OnInit(EventArgs e) in c:\AjaxControlToolkit_Admin\Release\AjaxControlToolkit\ToolkitScriptManager\ToolkitScriptManager.cs:line 198
  at System.Web.UI.Control.InitRecursive(Control namingContainer)
  at System.Web.UI.Control.InitRecursive(Control namingContainer)
  at System.Web.UI.Control.InitRecursive(Control namingContainer)
  at System.Web.UI.Control.InitRecursive(Control namingContainer)
  at System.Web.UI.Control.InitRecursive(Control namingContainer)
  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Run Code Online (Sandbox Code Playgroud)

该错误似乎是CodePlex中的已知问题,但这对我没有多大帮助.这是一个解释这个问题的链接:http: //dotnetdebug.ne​​t/2008/05/25/ajaxcontroltoolkit-toolkitscriptmanager-stringgethashcode-and-mixing-32bit-and-64bit-machinesprocesses/

我没有使用负载平衡,我想知道为什么我的应用程序将在32位和64位模式之间切换.

可能是必须为64位架构或类似的东西编译DLL吗?我应该注意哪些奇怪的问题可能导致我这个问题?

小智 3

看起来 String.GetHashCode() 结果会根据 dll 编译的指令集而变化。我无法解释为什么当您的 .NET 2.0+ 应用程序池都是 64 位时,会在框架内发生这种情况,但是如果您愿意从 codeplex 获取最新的源代码并更改其中的几行,则可以尝试一个解决方案工具包脚本管理器。

我不知道为什么没有根据可用的评论提交官方修复程序 - 也许是因为所有解决方案都像我的一样丑陋?

我尝试使用评论之一中描述的 SHA1 哈希例程来修复它 - 因此首先我在 ToolkitScriptManager 类中创建了 SHA1Managed 提供程序的静态实例,如下所示:

public class ToolkitScriptManager : ScriptManager
{
    private static System.Security.Cryptography.SHA1Managed s = new System.Security.Cryptography.SHA1Managed();
Run Code Online (Sandbox Code Playgroud)

...

然后有两个地方使用了字符串哈希码,我在 SerializeScriptEntries 函数中注释掉并替换了它们:

//serializedScriptEntries.Append(scriptEntry.Name.GetHashCode().ToString("x", CultureInfo.InvariantCulture));
serializedScriptEntries.Append(Convert.ToBase64String(s.ComputeHash(System.Text.Encoding.UTF8.GetBytes(scriptEntry.Name))));
Run Code Online (Sandbox Code Playgroud)

然后在 DeserializeScriptEntries 函数中:

//string hashCode = resourceName.GetHashCode().ToString("x", CultureInfo.InvariantCulture);
string hashCode = Convert.ToBase64String(s.ComputeHash(System.Text.Encoding.UTF8.GetBytes(resourceName)));
Run Code Online (Sandbox Code Playgroud)

也许更简单的方法允许我们只访问 64 位 GetHashCode 方法来序列化此字符串,以便我们为 32 位和 64 位调用获得相同的结果...