AJAX不能在ASP.NET中工作

时间:2022-09-27 03:18:21

I have .NET 4.0 and .NET 2.0 installed in my computer I tried running a AJAX.NET application with Asynchronous Triggered Timer Tick function and my page is reloading i.e. (Asynchronouspostback is not working). I tried changing my App Pool to Classic .NET 4.0 and I am getting error

我在我的计算机上安装了.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.

And when I change my App Pool to Classic .NET 2.0 page is being displayed but being postback'd upon timer intervals.

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

Is there anything more I should add to my Web.Config file

还有什么我应该添加到我的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>

and my AJAX.NET code is

我的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>

1 个解决方案

#1


1  

You can fix the isapi and cgi restrictions problem by opening IIS Manager, select the server, and double-clicking on the ISAPI and CGI Restrictions icon (assuming win 7 or win server 2008).

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

In the resulting screen, right click on each entry for ASP.NET v2.0.50727 (assuming a 64-bit OS; will only be one in 32-bit), select Edit... and check the Allow extension path to execute checkbox.

在结果屏幕中,右键单击ASP.NET v2.0.50727的每个条目(假设为64位操作系统;仅为32位中的一个),选择编辑...并选中允许执行扩展路径复选框。

This should allow ASP.Net 2.0 apps to run.

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

As far as the page posting back, the best suggestion is to wrap it in a separate update panel:

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

<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>

You may also want to consider increasing the timer interval from 200 milliseconds unless you absolutely need it that often (I have modified it above to be 2 seconds).

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

There is also one other setting to check: if you migrated this app from a .Net 1.1 application, you may have the <xhtmlConformance mode="Legacy" /> tag left over in your web.config.

还有一个要检查的设置:如果您从.Net 1.1应用程序迁移此应用程序,则可能在web.config中遗留了 标记。

If this is the case, this will absolutely cause this problem, as reported by Scott Guthrie of Microsoft fame.

如果是这种情况,这将绝对导致这个问题,正如微软成名的Scott Guthrie报道的那样。

#1


1  

You can fix the isapi and cgi restrictions problem by opening IIS Manager, select the server, and double-clicking on the ISAPI and CGI Restrictions icon (assuming win 7 or win server 2008).

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

In the resulting screen, right click on each entry for ASP.NET v2.0.50727 (assuming a 64-bit OS; will only be one in 32-bit), select Edit... and check the Allow extension path to execute checkbox.

在结果屏幕中,右键单击ASP.NET v2.0.50727的每个条目(假设为64位操作系统;仅为32位中的一个),选择编辑...并选中允许执行扩展路径复选框。

This should allow ASP.Net 2.0 apps to run.

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

As far as the page posting back, the best suggestion is to wrap it in a separate update panel:

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

<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>

You may also want to consider increasing the timer interval from 200 milliseconds unless you absolutely need it that often (I have modified it above to be 2 seconds).

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

There is also one other setting to check: if you migrated this app from a .Net 1.1 application, you may have the <xhtmlConformance mode="Legacy" /> tag left over in your web.config.

还有一个要检查的设置:如果您从.Net 1.1应用程序迁移此应用程序,则可能在web.config中遗留了 标记。

If this is the case, this will absolutely cause this problem, as reported by Scott Guthrie of Microsoft fame.

如果是这种情况,这将绝对导致这个问题,正如微软成名的Scott Guthrie报道的那样。