AJAX不工作在ASP.NET [英] AJAX not working in ASP.NET

查看:165
本文介绍了AJAX不工作在ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有.NET 4.0和.NET 2.0安装在我的电脑上我试图运行与异步触发计时器滴答功能的AJAX.NET应用程序,我的网页是重装IE(Asynchronouspostback不工作)。我试图改变我的应用程序池,以经典.net 4.0 ,我收到错误

  HTTP错误404.2  - 未找到
因为Web服务器上的ISAPI和CGI限制列表设置您请求的页面无法送达。
 

当我改变我的应用程序池,以经典.net 2.0 显示页面,但在定时器的时间间隔被postback'd。

有什么更多的我应该添加到我的web.config文件

 <结构>
    <的System.Web>
    <网页enableEventValidation =假的EnableViewState =假enableViewStateMac =假>
      <控制>
        <添加标签preFIX =ASP的命名空间=的System.Web.UI集结号=System.Web.Extensions程序,版本= 1.0.61025.0,文化=中性公钥= 31BF3856AD364E35/>
        <添加标签preFIX =ASP的命名空间=System.Web.UI.WebControls集结号=System.Web.Extensions程序,版本= 1.0.61025.0,文化=中性公钥= 31BF3856AD364E35/>
      < /控制>
    < /页>
        <的httpRuntime maxRequestLength的=32768executionTimeout =3600/>
    < HttpHandlers的>
      <加上动词=GET,HEAD路径=的ScriptResource.axdTYPE =System.Web.Handlers.ScriptResourceHandler,System.Web.Extensions程序,版本= 1.0.61025.0,文化=中性公钥= 31BF3856AD364E35验证= 假/>
    < / HttpHandlers的>
    <的HttpModules>
      <添加名称=ScriptModuleTYPE =System.Web.Handlers.ScriptModule,System.Web.Extensions程序,版本= 1.0.61025.0,文化=中性公钥= 31bf3856ad364e35/>
    < / HttpModules的>
    <编译defaultLanguage =C#调试=假>
      <组件>
        <添加组件=System.Web.Extensions程序,版本= 1.0.61025.0,文化=中性公钥= 31BF3856AD364E35/>
      < /组件>
    < /编译>
    < /system.web>
< /结构>
 

和我AJAX.NET code是

 < ASP:ScriptManager的ID =ScriptManager1=服务器的EnablePartialRendering =真/>
        < ASP:定时器ID =定时器1=服务器间隔=200ontick =Timer1_Tick/>
        < ASP:UpdatePanel的ID =UpdatePanel1=服务器的UpdateMode =条件>
        <的ContentTemplate>
        < /的ContentTemplate>
        <触发器>
            < ASP:AsyncPostBackTrigger控件ID =定时器事件名称=嘀/>
        < /触发器>
        < / ASP:UpdatePanel的>
 

解决方案

您可以通过打开IIS管理器修复ISAPI和CGI限制的问题,选择服务器,并在ISAPI和CGI限制图标双击(假定赢7或赢服务器2008)。

在出现的屏幕中,右键单击每个条目ASP.NET V2.0.50727(假设为64位操作系统,只会有一个32位),选择编辑... 并检查允许执行扩展路径复选框。

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

至于页面回发,最好的建议是把它包在一个单独的更新面板:

 < ASP:UpdatePanel中=服务器的UpdateMode =条件ChildrenAsTriggers =假
    ID =upTimer>
    <的ContentTemplate>
        < ASP:定时器ID =定时器1=服务器间隔=2000ontick =Timer1_Tick/>
    < /的ContentTemplate>
< / ASP:UpdatePanel的>
 

您可能还需要考虑从200毫秒增加的时间间隔,除非你绝对需要它经常(我已经修改了它上面是2秒)。

还有另外一个设置检查:如果你迁移从.NET 1.1应用程序这个应用程序,你可能有< xhtmlConformance模式=遗产/> 标签遗留在你的web.config。

如果是这种情况,这将绝对导致此问题,<一href="http://weblogs.asp.net/scottgu/archive/2006/12/10/gotcha-don-t-use-xhtmlconformance-mode-legacy-with-asp-net-ajax.aspx"相对=nofollow>报告的微软名气斯科特·格思里。

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

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.

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

<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

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

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.

This should allow ASP.Net 2.0 apps to run.

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

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.

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

这篇关于AJAX不工作在ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆