‘Sys’未定义

‘Sys’未定义

原因:使用ASP.NET Web Site模板创建了一个网站,但是却在页面中放置了一个ScriptManager控件。

解决方法:使用ASP.NET AJAX-Enabled Web Site模板创建网站。

 

后记:关于sys is undefined的详细讨论请参考下面这篇文章:

http://weblogs.asp.net/chrisri/archive/2007/02/02/demystifying-sys-is-undefined.aspx

Are you running into this error on your ASP.NET AJAX enabled web site? Does it only happen on some machines or on some browsers? Here’s how you can get to the bottom of it.

Here's a little background on what is happening…

When you have a ScriptManager on a page, ASP.NET AJAX will render a few script tags to load the various ASP.NET AJAX Scripts, and some inline script to get everything initialized and running. If you view source on the page as rendered by your browser, you should see something like this:

<script type="text/javascript">
Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls([], [], [], 90);
</script>

When the browser goes to run that code, it’s going to expect Sys.WebForms.PageRequestManager to be defined somewhere. That somewhere happens to be in the other scripts that are loaded from script tags that look like this:

<script src="/MyWebApp/ScriptResource.axd?[snip - long query string]" type="text/javascript"></script>

If the browser fails to load those scripts, the script engine can’t find the definition for Sys, Sys.WebForms, Sys.WebFormsPageRequestManager, and thus the error.

So why would those scripts fail to load? We’ve seen several reasons:

1. The browser fails to load the compressed script

This is usually the case if you get the error on IE6, but not on other browsers.

The Script Resource Handler – ScriptResource.axd compresses the scripts before returning them to the browser. In pre-RTM releases, the handler did it all the time for all browsers, and it wasn’t configurable. There is an issue in one of the components of IE6 that prevents it from loading compressed scripts correctly. See KB article here. In RTM builds, we’ve made two fixes for this. One, we don’t compress if IE6 is the browser client. Two, we’ve now made compression configurable. Here’s how you can toggle the web.config.

How do you fix it? First, make sure you are using the AJAX Extensions 1.0 RTM release. That alone should be enough. You can also try turning off compression by editing your web.config to have the following:

<system.web.extensions>
<scripting>
<scriptResourceHandler enableCompression="false" enableCaching="true" />
</scripting>
</system.web.extensions>

2. The required configuration for ScriptResourceHandler doesn’t exist for the web.config for your application

Make sure your web.config contains the entries from the default web.config file provided with the extensions install. (default location: C:/Program Files/Microsoft ASP.NET/ASP.NET 2.0 AJAX Extensions/v1.0.61025)

3. The virtual directory you are using for your web, isn’t correctly marked as an application (thus the configuration isn’t getting loaded) - This would happen for IIS webs.

Make sure that you are using a Web Application, and not just a Virtual Directory 

4. ScriptResource.axd requests return 404

This usually points to a mis-configuration of ASP.NET as a whole. On a default installation of ASP.NET, any web request to a resource ending in .axd is passed from IIS to ASP.NET via an isapi mapping. Additionally the mapping is configured to not check if the file exists. If that mapping does not exist, or the check if file exists isn't disabled, then IIS will attempt to find the physical file ScriptResource.axd, won't find it, and return 404.

You can check to see if this is the problem by coipy/pasting the full url to ScriptResource.axd from here, and seeing what it returns

<script src="/MyWebApp/ScriptResource.axd?[snip - long query string]" type="text/javascript"></script>

How do you fix this? If ASP.NET isn't properly installed at all, you can run the "aspnet_regiis.exe" command line tool to fix it up. It's located in C:/WINDOWS/Microsoft.Net/Framework/v2.0.50727. You can run "aspnet_regiis -i -enable", which does the full registration of ASP.NET with IIS and makes sure the ISAPI is enabled in IIS6. You can also run "aspnet_regiis -s w3svc/1/root/MyWebApp" to only fix up the registration for your web application.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值