C# System.Web.HttpException: 这是一个无效的脚本资源请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1096793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
System.Web.HttpException: This is an invalid script resource request
提问by januszstabik
I get this error when pushing our website to our clients production server however the page works absolutely fine on their dev / test servers. What causes this error (considering I am not using any web resources myself, though I am using the asp.net ajax toolkit).
将我们的网站推送到我们的客户生产服务器时出现此错误,但是该页面在他们的开发/测试服务器上运行得非常好。导致此错误的原因(考虑到我自己没有使用任何 Web 资源,尽管我使用的是 asp.net ajax 工具包)。
回答by Atanas Korchev
You can check the urls which were generating this error. Web resources (used by the Ajax Toolkit) rely on a query string argument. If that argument is altered in some way (perhaps by some malicious user) the HTTP handler will throw exception that it cannot find the requested web resource.
您可以检查产生此错误的网址。Web 资源(由 Ajax Toolkit 使用)依赖于查询字符串参数。如果该参数以某种方式(可能被某些恶意用户)更改,则 HTTP 处理程序将抛出无法找到请求的 Web 资源的异常。
回答by Rob Levine
Can you get a full stack trace on this error? There will be one in the server event log (system or application, can't remember which)?
你能得到关于这个错误的完整堆栈跟踪吗?服务器事件日志中会有一个(系统或应用程序,不记得是哪个)?
There are various parts of ASP.NET that use script resources, and at least two slightly obscure causes of them failing with this sort of error I can think of.
ASP.NET 的各个部分都使用脚本资源,并且至少有两个稍微模糊的原因导致它们因我能想到的此类错误而失败。
- believe it or not, if your dlls have embedded resources in them, and they are dated in the future this will happen (if you ever compile dlls in the UK and then immediately deploy them to US web servers you'll be well aware of this issue!). I can't remember the event log error this shows, but would know if I saw it - and it is not immediately obvious.
- if you have a load balancer routing requests between multiple servers without being "sticky", and your servers have different machine keys, then the request will fail because the encrypted querystring identifying the resource will not be decryptable on another server. This will cause a stack trace that includes various crypto types in it.
- 信不信由你,如果你的 dll 中嵌入了资源,并且它们在未来过时了,这将会发生(如果你曾经在英国编译过 dll,然后立即将它们部署到美国网络服务器,你会很清楚这一点问题!)。我不记得这里显示的事件日志错误,但是如果我看到它就会知道 - 而且它不是很明显。
- 如果您有一个负载平衡器在多个服务器之间路由请求而没有“粘性”,并且您的服务器具有不同的机器密钥,那么请求将失败,因为标识资源的加密查询字符串将无法在另一台服务器上解密。这将导致堆栈跟踪,其中包含各种加密类型。
There are lots of other causes (such as incorrect uris, or querystrings getting corrupted as mentioned above), but having a full stack trace will help here.
还有很多其他原因(例如不正确的 uri,或者如上所述的查询字符串被破坏),但是拥有完整的堆栈跟踪将在这里有所帮助。
回答by adinas
If indeed you are using multiple servers try the following: Add to your web.config:
如果您确实使用了多个服务器,请尝试以下操作:添加到您的 web.config:
<machineKey
validationKey="21F090935F6E49C2C797F69BBAAD8402ABD2EE0B667A8B44EA7DD4374267A75D7
AD972A119482D15A4127461DB1DC347C1A63AE5F1CCFAACFF1B72A7F0A281B"
decryptionKey="ABAA84D7EC4BB56D75D217CECFFB9628809BDB8BF91CFCD64568A145BE59719F"
validation="SHA1"
decryption="AES"
/>
But generate the validationKey and decryptionKey yourself using the code examples found here: http://msdn.microsoft.com/en-us/library/ms998288.aspxThe above link also explains more about this solution so check it out, look for Web Farm Deployment Considerationson that page
但是使用此处找到的代码示例自己生成验证密钥和解密密钥:http: //msdn.microsoft.com/en-us/library/ms998288.aspx上面的链接还解释了有关此解决方案的更多信息,因此请查看,查找Web该页面上的场部署注意事项
回答by januszstabik
The error in the end was due to some URL re-writing that was occuring the server to which the admins hadn't told us about.! Watch out for that one
最后的错误是由于管理员没有告诉我们的服务器发生了一些 URL 重写。!当心那个
回答by coderman
I used to get this annoying error all the time. Users are indeed affected by this error. We used to get complaints of pages not loading properly. After trying many things like adding DOCTYPE
the error did not go away completely. Then we tried storing all the VIEWSTATE
in session. Violà no more errors. If your application has a bloated view state like ours then you will see this error in the logs. Often.
我曾经一直遇到这个烦人的错误。用户确实受到此错误的影响。我们过去常常抱怨页面加载不正确。在尝试了许多诸如添加DOCTYPE
错误之类的事情之后,并没有完全消失。然后我们尝试存储所有VIEWSTATE
会话。Violà 不再有错误。如果您的应用程序具有像我们这样的臃肿视图状态,那么您将在日志中看到此错误。经常。