3

我們有一個帶有2個web.config文件的Web應用程序。我在ASP.NET頁面中使用telerik:RadScriptManager控件。有一個Web資源文件(WebResource.axd),這個控件需要訪問它的ScriptReferences。我認爲這個.axd文件包含Telerik控件的JavaScript文件。我們所有的Rad控件都是在一個名爲「admin」的獨立Web應用程序(.csproj)項目中實現的。根web應用程序項目(.csproj)有一個名爲「admin」的文件夾,其中包含所有admin項目文件,包括admin web.config。我在這裏遇到問題的頁面也位於管理員項目中。我認爲它試圖訪問根文件夾中的.axd文件,而不是「/ admin」文件夾。 (在我更改HTTP Handler的路徑後,在我的問題的底部發現另一個錯誤)。 如何讓應用程序讀取〜/ admin/Telerik.Web.UI.WebResource.axd中的WebResource.axd文件,而不是〜/ Telerik.Web.UI.WebResource.axd?我猜這3個JavaScript錯誤是由於此資源問題導致的,因爲當我明確導航到admin文件夾URL中的資源時,我可以看到ASP.NET AJAX Control Toolkit JavaScript代碼。HTTP處理程序無法在嵌套的Web應用程序文件夾中找到axd文件:Telerik RadScriptManager在〜/ admin /文件夾中找不到WebResource.axd

源代碼:

<telerik:RadScriptManager ID="RadScriptManager1" runat="server"> 
     <%--<Scripts> 
      <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" /> 
      <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" /> 
     </Scripts>--%> 
    </telerik:RadScriptManager> 

根應用程序的web.config中的代碼:

<location path="Telerik.Web.UI.WebResource.axd"> 
    <system.web> 
    <authorization> 
     <allow users="*"/> 
    </authorization> 
    </system.web> 
</location> 

以下是該網站(根)應用項目的web.config HTTP處理程序:

<httpHandlers> 
     <add path="/services/social.axd" verb="GET,POST" type="Acu.Cms.Modules.Social.PeopleHandler, Acu.Cms.Modules.Social"/> 
     <add verb="*" path="AcuLanapCaptcha.axd" type="Lanap.BotDetect.AcuCaptchaHandler, Lanap.BotDetect"/> 
     <add verb="*" path="LanapCaptcha.aspx" type="Lanap.BotDetect.CaptchaHandler, Lanap.BotDetect"/> 
     <add path="*.cmsx" verb="*" type="Acu.Cms.Web.HttpCmsRequestHandler, Acu.Cms"/> 
     <add path="image.acux" verb="GET" type="Acu.Web.Imaging.WebImageHandler, Acu.Web.Imaging"/> 
     <add path="media.acux" verb="GET" type="Acu.Cms.Web.CmsWebMediaHandler, Acu.Cms"/> 
     <remove verb="*" path="*.asmx" /> 
     <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" /> 
     <add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="true" /> 
    </httpHandlers> 

這裏有管理員(虛擬目錄)的應用程序項目的web.config HTTP處理程序:

<httpHandlers> 
     <remove path="LanapCaptcha.aspx" verb="*" /> 
     <remove path="AcuLanapCaptcha.aspx" verb="*" /> 
     <remove verb="*" path="*.asmx" /> 
     <add path="Authenticator.ashx" verb="GET,POST" type="Acu.Cms.Website.Admin.Authenticator, Acu.Cms.Website.Admin" /> 
     <add verb="*" path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.RadUploadProgressHandler" validate="false" /> 
     <add verb="*" path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.Upload.RadUploadProgressHandler, Telerik.Web.UI" /> 
     <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add verb="*" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" validate="false" /> 
     <!--ScriptResourceHandler.axd is the resource handler URL used to serve all of the javascript files found in the Microsoft AJAX Library--> 
     <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" /> 
     <add path="ChartImage.axd" type="Telerik.Web.UI.ChartHttpHandler" verb="*" validate="false" /> 
     <add path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler" verb="*" validate="false" /> 
     <add path="Telerik.Web.UI.DialogHandler.aspx" type="Telerik.Web.UI.DialogHandler" verb="*" validate="false" /> 
     <add verb="*" validate="false" path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler, Telerik.Web.UI" /> 
    </httpHandlers> 

JavaScript錯誤#1:

ASP.NET AJAX客戶端框架未能加載。

<script type="text/javascript"> 
//<![CDATA[ 
if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.'); 
function WebForm_OnSubmit() { 
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false; 
return true; 
} 

JavaScript錯誤#2:

Sys系統沒有定義

<script type="text/javascript"> 
//<![CDATA[ 
Sys.WebForms.PageRequestManager._initialize('RadScriptManager1', document.getElementById('editorform')); 
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tctl00SU'], [], [], 90); 
//]]> 
</script> 

JavaScript錯誤#3:

RadEditorCommandList不定義

RadEditorCommandList['Edit Link'] = function(commandName, editor, oTool) 
{ 
_editor = editor; 
_point = editor.CreateRestorePoint(); 
var selection = editor.GetSelection(); 
var pe = selection.GetParentElement(); 
var id = ''; 
if (pe && pe.tagName.toLowerCase() == 'a' && pe.attributes['cms:asset_id']) { 
id = pe.attributes['cms:asset_id'].value; 
} 
window.top.InlineLinkEditor.selection = selection.GetText(); 
window.top.InlineLinkEditor.show('elementid=' + $('__elementId').value + '&xrefid=' + id + '&html=' + encodeURIComponent(selection.GetHtmlText()), editLink, null); 
}; 

============

排除一些更多...

我試圖改變我的管理項目的web.config WebResource的路徑HTTP處理程序爲「/ admin/...」,但後來我得到新的錯誤。

<add verb="*" path="/admin/Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" validate="false" /> 

新的錯誤:

Server Error in '/' Application. 
'~/Telerik.Web.UI.WebResource.axd' is missing in web.config. RadScriptManager requires a HttpHandler registration in web.config. Please, use the control Smart Tag to add the handler automatically, or see the help for more information: Controls > RadScriptManager 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: '~/Telerik.Web.UI.WebResource.axd' is missing in web.config. RadScriptManager requires a HttpHandler registration in web.config. Please, use the control Smart Tag to add the handler automatically, or see the help for more information: Controls > RadScriptManager 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 

[InvalidOperationException: '~/Telerik.Web.UI.WebResource.axd' is missing in web.config. RadScriptManager requires a HttpHandler registration in web.config. Please, use the control Smart Tag to add the handler automatically, or see the help for more information: Controls > RadScriptManager] 
    Telerik.Web.UI.RadScriptManager.OnPreRender(EventArgs e) +169 
    System.Web.UI.Control.PreRenderRecursiveInternal() +80 
    System.Web.UI.Control.PreRenderRecursiveInternal() +171 
    System.Web.UI.Control.PreRenderRecursiveInternal() +171 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842 


Version Information: Microsoft .NET Framework Version:2.0.50727.3623; ASP.NET Version:2.0.50727.3618 

試圖從這篇文章中獲得一些信息:

http://weblogs.asp.net/asptest/archive/2008/10/06/asp-net-ajax-and-http-handlers-a-cautionary-tale.aspx

使用此方法解決問題,也試過..它有助於引導我一點,但是進來了完成我的具體問題:

http://www.telerik.com/help/aspnet-ajax/introduction-troubleshooting.html

回答

2

原來,ASP.NET着眼於根web.config中的HTTP處理程序,然後再着眼於HTTP處理程序在虛擬目錄的web.config文件。所以當它出現在我標記爲下面的「罪魁禍首」的那一行時,它從未到達虛擬目錄web.config文件中的行。所以我只在「罪魁禍首」HTTP處理程序上面添加了另一行。

根網站文件夾中的web.config HTTP處理程序:

<httpHandlers> 
    <add path="/services/social.axd" verb="GET,POST" type="Acu.Cms.Modules.Social.PeopleHandler, Acu.Cms.Modules.Social"/> 
    <add verb="*" path="AcuLanapCaptcha.axd" type="Lanap.BotDetect.AcuCaptchaHandler, Lanap.BotDetect"/> 
    <add verb="*" path="LanapCaptcha.aspx" type="Lanap.BotDetect.CaptchaHandler, Lanap.BotDetect"/> 
    <add path="*.cmsx" verb="*" type="Acu.Cms.Web.HttpCmsRequestHandler, Acu.Cms"/> 
    <add path="image.acux" verb="GET" type="Acu.Web.Imaging.WebImageHandler, Acu.Web.Imaging"/> 
    <add path="media.acux" verb="GET" type="Acu.Cms.Web.CmsWebMediaHandler, Acu.Cms"/> 
    <remove verb="*" path="*.asmx" /> 
    <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" /> 
    <!-- FIXED WITH THIS LINE --><add verb="*" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" validate="false" /> 
    <!-- CULPRIT ............ --><add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="true" /> 
</httpHandlers> 

還增加了這個虛擬目錄的web.config:

<handlers> 

...刪除等處理

 <add name="Telerik.Web.UI.WebResource" 
      path="Telerik.Web.UI.WebResource.axd" 
      type="Telerik.Web.UI.WebResource, Telerik.Web.UI" 
      verb="*" /> 

    </handlers> 

...另一種方法是將「admin/*」添加到路徑web.config屬性的開頭。如果該處理程序在RadEditor或其他控件中使用,則必須正確引用它。

相關問題