简体   繁体   English

AJAX在ASP.NET中不起作用

[英]AJAX not working in ASP.NET

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 ie (Asynchronouspostback is not working). 我在计算机上安装了.NET 4.0和.NET 2.0,我尝试运行具有异步触发的计时器刻度线功能的AJAX.NET应用程序,并且页面正在重新加载(即,Asynchronouspostback无法正常工作)。 I tried changing my App Pool to Classic .NET 4.0 and I am getting error 我尝试将我的应用程序池更改为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>

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). 您可以通过以下方式解决isapi和cgi限制问题:打开IIS管理器,选择服务器,然后双击“ ISAPI和CGI限制”图标(假设使用win 7或win server 2008)。

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位OS;将仅为32位之一),选择“ Edit...然后选中“ Allow extension path to execute复选框。

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中可能会<xhtmlConformance mode="Legacy" />标记。

If this is the case, this will absolutely cause this problem, as reported by Scott Guthrie of Microsoft fame. 如果是这样的话,这将绝对会导致此问题, 正如 Microsoft名望的Scott Guthrie所报告的那样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM