maintainScrollPositionOnPostBack不起作用,WebForm_SaveScrollPositionSubmit is not defined

来源:互联网 发布:乐乎青年公寓联系电话 编辑:程序博客网 时间:2024/05/17 03:18

asp.net的页面,滚动条位置刷新后不保存上一次位置。


使用的方法为在Web.config添加

<pages maintainScrollPositionOnPostBack="true"/>


但一直不起作用,页面显示 JS报错:


Uncaught ReferenceError: WebForm_SaveScrollPositionSubmit is not defined 

Failed to load resource: the server responded with a status of 404 (Not Found) 


开始认为是Chrome不支持,最后测试发现是


<httpRuntime 节点影响了,

添加 <httpRuntime targetFramework="4.5"  这个属性后正常,汗!


这是为什么?

Machine.config 文件或根 Web.config 文件中未显式定义 httpRuntime 元素。 但是,以下设置是系统初始化的默认值。 如果需要自定义此节,必须在配置文件中创建它并且只定义那些需要自定义的特性。


<httpRuntime    apartmentThreading="false"   appRequestQueueLimit="5000"   delayNotificationTimeout="5"   enable="true"   enableHeaderChecking="true"   enableKernelOutputCache="true"   enableVersionHeader="true"   encoderType = "System.Web.Util.HttpEncoder"   executionTimeout="110"   maxQueryStringLength = "2048"   maxRequestLength="4096"   maxUrlLength = "260"   maxWaitChangeNotification="0"   minFreeThreads="8"   minLocalRequestFreeThreads="4"   relaxedUrlToFileSystemMapping = "False"   requestLengthDiskThreshold="80"   requestPathInvalidCharacters = "<,>,*,%,&,:,\"   requestValidationMode = "4.0"   requestValidationType = "System.Web.Util.RequestValidator"   requireRootedSaveAsPath="true"   sendCacheControlHeader="true"   shutdownTimeout="90"   useFullyQualifiedRedirectUrl="false"   waitChangeNotification="0" />

是因为运行环境与Machine.config不一致?奇怪。


重启动又不行,。。。。


发现和

<machineKey validationKey="3FF1E929BC0534950B0920A7B59FA698BD02DFE8"  validation="SHA1"  decryptionKey="280450BB36319B474C996B506A95AEDF9B51211B1D2B7A77" decryption="3DES"/>

有关。

验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保 <machineKey> 配置指定了相同的 validationKey 和验证算法。不能在群集中使用 AutoGenerate

主要的原因是解决提交了名为__VIEWSTATE的数据,ASP.NET的验证视图状态的时候失败。而加的解决方案。



1、去掉 runat="server"

2、添加enableEventValidation="false" enableViewStateMac="false"
或在webconfig中添加<pages enableEventValidation="false" enableViewStateMac="false" />

3、在webconfig中添加:<machineKey validation="3DES" validationKey="319B474B1D2B7A87C996B280450BB36506A95AEDF9B51211" decryption="3DES" decryptionKey="280450BB36319B474C996B506A95AEDF9B51211B1D2B7A87" />



0 0