﻿{"id":197,"date":"2010-05-25T12:16:02","date_gmt":"2010-05-25T04:16:02","guid":{"rendered":"http:\/\/nick.workao.org\/?p=197"},"modified":"2010-05-25T12:16:02","modified_gmt":"2010-05-25T04:16:02","slug":"scriptresource-axd-invalid-viewstate-%e7%bb%8f%e5%b8%b8%e5%9c%a8-ie8-%e5%87%ba%e7%8e%b0%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/nick.txtcc.com\/index.php\/win\/197","title":{"rendered":"ScriptResource.axd : Invalid viewstate \u7ecf\u5e38\u5728 IE8 \u51fa\u73b0\u7684\u89e3\u51b3\u65b9\u6cd5"},"content":{"rendered":"<p>This issue is caused when the ScriptResource.axd querystring  parameters can not be decoded on the server. This error can be caused  from multiple issues with server configuration or the Browser&#8217;s  interaction with the server.<\/p>\n<p>The ScriptResource.axd contains all of the clientside javascript  routines for Ajax. Just because you include a scriptmanager that loads a  script file it will never appear as a ScriptResource.AXD &#8211; instead it  will be merely passed as the .js file you send if you reference a  external script file. In other words it is what the Microsoft Ajax  libraries inject into your HTML to allow them to access their javascript  functions they need for page manipulation.<\/p>\n<p>ASP.NET will use the machine key to encrypt the ScriptResource.axd (and  webresource.axd) url&#8217;s parameters(in querystring), and by default the  machinekey is a randomly generated one which may involve the current  time. By default there is a different machinekey on every machine, and  it changes when the application (w3svc.exe process) is recycled.<\/p>\n<p>If you are running a web farm you need to &#8220;hard code&#8221; the machinekey to  be the same for every server. This way a response from one web server  can be decrypted on another server. Like in the case one of your servers  goes down for maintenance and the users traffic is routed to another  server.<\/p>\n<p>You also need to &#8220;hard code&#8221; the machine key if you want to &#8220;survive&#8221;  application recycles.<\/p>\n<p>Here is instructions for &#8220;hard coding&#8221; the machine key:\n<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms998288.aspx\">http:\/\/msdn.microsoft.com\/en-us\/library\/ms998288.aspx<\/a><\/p>\n<p><strong>BUT WAIT&#8230;.<\/strong><\/p>\n<p>This error can be caused from a number of different issues. One of which  is having the wrong DOCTYPE for the style of page you are writing.  Especially with Internet Explorer 8.<\/p>\n<p>This error can be caused from having a DOCTYPE of XHTML. This is because  with XHTML all special characters should be encoded or all content  should be wrapped inside a CDATA section. In other words if you don&#8217;t  have prefect XHTML in some cases the browser will not parse your XHTML  correctly and the request to \/ScriptResource.axd will have scrambled  parameters<\/p>\n<p>Converting the DOCTYPE to HTML can solve the Viewstate issue.<\/p>\n<pre><!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\">\n<\/pre>\n<p>To This:<\/p>\n<pre><!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\"><\/pre>\n<p>Why does this solve the issue? The browser uses a different parsing  algorithm which is &#8220;looser&#8221; and can handle the non-compliant XHTML that  you might be outputting.<\/p>\n<p>One trick mentioned on the Internet to prevent the &#8220;Error :  \/ScriptResource.axd : Invalid viewstate.&#8221; without having to change the  DOCTYPE is to wrap your javascript in CDATA tags like this:<\/p>\n<pre><script>    \n    mycode;\n<\/script><\/pre>\n<p>would become:<\/p>\n<pre><script>\n\/\/ <![CDATA[    \n     mycode;\n\/\/ ]]>\n<\/script><\/pre>\n<p>Which is an attempt to get XHTML compliant. However, I have found  that while this is good practice, there are probably other issues what  will cause your HTML not be XMHTL compliant and changing DOCTYPES are  the best policy.<\/p>\n<p>{6230289B-5BEE-409e-932A-2F01FA407A92}<\/p>","protected":false},"excerpt":{"rendered":"<p>This issue is caused when the ScriptResource.axd querystring parameters can not be decoded on the se&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[141,140],"class_list":["post-197","post","type-post","status-publish","format-standard","hentry","category-win","tag-invalid-viewstate","tag-scriptresource-axd"],"_links":{"self":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=197"}],"version-history":[{"count":1,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/197\/revisions"}],"predecessor-version":[{"id":198,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/197\/revisions\/198"}],"wp:attachment":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}