Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Error message when you access a Web page that runs an AJAX 1.0-enabled ASP.NET 2.0 program: "A Runtime Error has occurred"
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.| Article ID | : | 936993 |
| Last Review | : | June 1, 2007 |
| Revision | : | 1.2 |
On This Page
SYMPTOMS
You receive the following error message when you access a Web page that runs an AJAX 1.0-enabled Microsoft ASP.NET 2.0 program:
A Runtime Error has occurred.
Do you wish to Debug?
Line: 5
Error: Access is Denied
This error message occurs if the following conditions are true:
| • | You use an <iframe> element in a Web page that points to another Web page from a different domain. |
| • | The Web page from a different domain uses ASP.NET AJAX server controls. |
| • | You perform an action in the <iframe> element that triggers an asynchronous postback operation. |
| • | In Microsoft Internet Explorer, you click to select the following check boxes under Browsing on the Advanced tab in Internet Options: | • | Disable script debugging (Internet Explorer) | | • | Disable script debugging (Other) |
|
Back to the top
CAUSE
This problem occurs because the Web page that contains the <iframe> element and the Web page to which the <iframe> element points are in different domains. The AJAX 1.0-enabled ASP.NET script fails when it tries to determine the offset of the content.
Back to the top
RESOLUTION
To resolve this problem, use one of the following methods.
Back to the top
Method 1
Make sure that the Web page that contains the <iframe> element and the Web page to which the <iframe> element points are in the same domain.
Back to the top
Method 2
Update the JavaScript files to avoid the error message. Use the external script files that exist in the AJAX Library package instead of the resource-based files that exist in the AJAX Extension package. To do this, follow these steps.
Step 1: Configure the Web page to use the script files instead of the resource-based files
| a. | Download and then extract the AJAX Library from the Microsoft Download Center.
The following file is available for download from the Microsoft Download Center:
Download the Microsoft AJAX Library package now. (http://ajax.asp.net/downloads/library/default.aspx?tabid=47&subtabid=471)
For more information about how to download Microsoft support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591 (http://kbalertz.com/Feedback.aspx?kbNumber=119591/) How to obtain Microsoft support files from online services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help prevent any unauthorized changes to the file.
|
| b. | On the Web page that contains the <iframe> element, specify a value for the ScriptPath attribute in the <ScriptManager> element. The following code looks for the scripts in a folder that is named Scripts in the application root directory.<asp:ScriptManager ID="ScriptManager1" runat="server" ScriptPath="~/Scripts" /> |
| c. | Copy the System.Web.Extensions folder in the AJAX Library into the Scripts folder. |
| d. | Access the ASPX page to confirm that the script files are called from the Scripts folder. To do this, click Source on the View menu in Internet Explorer. Locate the following two script tags.<script src="Scripts/System.Web.Extensions/1.0.61025.0/MicrosoftAjax.js" type="text/javascript"></script>
<script src="Scripts/System.Web.Extensions/1.0.61025.0/MicrosoftAjaxWebForms.js" type="text/javascript"></script>
|
Step 2: Modify the MicrosoftAjax.debug.js file to avoid the error message
You must use the MicrosoftAjax.debug.js file when the
debug attribute in the <compilation> element is set to True in the Web.config file. The MicrosoftAjax.debug.js file contains line breaks. To modify the MicrosoftAjax.debug.js file, follow these steps:
| a. | Open the MicrosoftAjax.debug.js file. This file is located in the following folder: Application Root Directory/Scripts/System.Web.Extensions/1.0.61025.0 |
| b. | Locate the following two lines of code. (There may be code between these two lines.)switch(Sys.Browser.agent) {
case Sys.Browser.InternetExplorer:
case Sys.Browser.Safari:
|
| c. | Paste the following code between the two lines of code that are listed in step 2b. If code exists between the two lines, replace the code.
New Code Sys.UI.DomElement.getLocation = function(element) {
if (element.self || element.nodeType === 9) return new Sys.UI.Point(0,0);
var clientRect = element.getBoundingClientRect();
if (!clientRect) {
return new Sys.UI.Point(0,0);
}
var ownerDocument = element.document.documentElement;
var offsetX = clientRect.left - 2 + ownerDocument.scrollLeft,
offsetY = clientRect.top - 2 + ownerDocument.scrollTop;
try {
var f = element.ownerDocument.parentWindow.frameElement || null;
if (f) {
var offset = 2 - (f.frameBorder || 1) * 2;
offsetX += offset;
offsetY += offset;
}
}
catch(ex) {
}
return new Sys.UI.Point(offsetX, offsetY);
}
break;
|
| d. | Save the MicrosoftAjax.debug.js file. |
| e. | Open the Web.config file in the ASP.NET program, and then set the debug attribute to True in the <compilation> element. |
| f. | Save the Web page. |
Step 3: Modify the MicrosoftAjax.js file to avoid the error message
The MicrosoftAjax.js file is the release version of the MicrosoftAjax.debug.js file. The MicrosoftAjax.js does not contain line breaks. To modify the MicrosoftAjax.js file, follow these steps:
| a. | Open the MicrosoftAjax.js file in the Scripts folder. |
| b. | Locate the following two lines of code. (There may be code between these two lines.) switch(Sys.Browser.agent){case Sys.Browser.InternetExplorer:
case Sys.Browser.Safari: |
| c. | Paste the following code between the two lines of code that are listed in step 3b. If code exists between the two lines, replace the code.
New CodeSys.UI.DomElement.getLocation=function(a){if(a.self||a.nodeType===9) return new Sys.UI.Point(0,0);
var b=a.getBoundingClientRect();
if(!b) return new Sys.UI.Point(0,0);
var c=a.document.documentElement,d=b.left-2+c.scrollLeft,e=b.top-2+c.scrollTop;
try{var g=a.ownerDocument.parentWindow.frameElement||null;
if(g){var f=2-(g.frameBorder||1)*2;
d+=f;e+=f}}catch(h){}return new Sys.UI.Point(d,e)};
break; |
| d. | Save the MicrosoftAjax.js file. |
| e. | Open the Web.config file in the ASP.NET program, and then set the debug attribute to True in the <compilation> element. |
| f. | Save the Web page. |
Back to the top
STATUS
This behavior is by design.
Back to the top
MORE INFORMATION
For more information about the <iframe> element, visit the following Microsoft Developer Network (MSDN) Web site:
For more information about ASP.NET AJAX, visit the following Microsoft Web site:
Back to the top
Back to the top
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please