【问题标题】:AJAX not working in ASP.NETAJAX 在 ASP.NET 中不起作用
【发布时间】:2012-01-12 17:23:53
【问题描述】:

我的计算机中安装了 .NET 4.0 和 .NET 2.0 我尝试运行具有异步触发定时器滴答功能的 AJAX.NET 应用程序,并且我的页面正在重新加载,即(异步回发不起作用)。我尝试将我的应用程序池更改为Classic .NET 4.0,但出现错误

HTTP Error 404.2 - Not Found
The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server.

当我将我的应用程序池更改为Classic .NET 2.0 时,页面正在显示,但在计时器间隔后被回发。

还有什么我应该添加到我的 Web.Config 文件中的吗

<configuration>
    <system.web>
    <pages enableEventValidation="false" enableViewState="false" enableViewStateMac="false">
      <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </controls>
    </pages>
        <httpRuntime maxRequestLength="32768" executionTimeout="3600"/>
    <httpHandlers>
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
    </httpHandlers>
    <httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </httpModules>
    <compilation defaultLanguage="c#" debug="false">
      <assemblies>
        <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
    </compilation>
    </system.web>
</configuration>

而我的 AJAX.NET 代码是

        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
        <asp:Timer ID="Timer1" runat="server" Interval="200" ontick="Timer1_Tick" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
        </Triggers>
        </asp:UpdatePanel>

【问题讨论】:

    标签: .net ajax.net


    【解决方案1】:

    您可以通过打开 IIS 管理器、选择服务器并双击 ISAPI 和 CGI​​ 限制图标(假设 win 7 或 win server 2008)来修复 isapi 和 cgi 限制问题。

    在结果屏幕中,右键单击 ASP.NET v2.0.50727 的每个条目(假设是 64 位操作系统;只有 32 位操作系统),选择 Edit... 并选中 Allow extension path to execute 复选框。

    这应该允许 ASP.Net 2.0 应用程序运行。

    就回发页面而言,最好的建议是将其包装在单独的更新面板中:

    <asp:UpdatePanel runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false"
        ID="upTimer">
        <ContentTemplate>
            <asp:Timer ID="Timer1" runat="server" Interval="2000" ontick="Timer1_Tick" />
        </ContentTemplate>
    </asp:UpdatePanel>
    

    您可能还需要考虑将计时器间隔从 200 毫秒增加到 200 毫秒,除非您绝对经常需要它(我在上面将其修改为 2 秒)。

    还有一个其他设置需要检查:如果您从 .Net 1.1 应用程序迁移此应用程序,您的 web.config 中可能会留下 &lt;xhtmlConformance mode="Legacy" /&gt; 标记。

    如果是这样的话,这绝对会导致这个问题,微软名气as reported by Scott Guthrie

    【讨论】:

    • 感谢您的回答,但很抱歉其不完整!我对 AJAX.NET Timer Tick 问题有很大的疑问。即使在执行此操作后,仍然页面每 2 秒重新加载一次。
    • 不知道为什么会这样(看起来会更多),但您可能需要考虑更改您的 Timer 间隔。目前,它设置为 200 毫秒,这可能会导致页面混乱。
    • 我已经用回发问题的可能解决方案更新了答案。
    • 不管它改成什么。页面不应该重新加载吗?我在 VS10 中使用了相同的属性,并在 cassini 服务器中执行了数百个应用程序,一切正常,没有任何问题,但是当我在 IIS 中运行相同的代码时,我遇到了所有这些问题。
    • 还发现了另外一个,很可能是问题的原因。答案再次更新。
    猜你喜欢
    • 1970-01-01
    • 2017-06-10
    • 2012-06-11
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多