2009-06-29 94 views
1

我有一个自定义ASPX页面,我部署在ISV文件夹中。页面 包含一个ScriptManager控件。动态CRM 4.0,在自定义ASPX页面上使用AJAX

为了加载页面,我需要在某处包含AJAX配置设置。对于自定义网站,我可以将配置放在web.config文件中。但是对于Dynamics CRM,不支持对web.config的更改...并尽可能地保留“受支持”的一面。

我试图使用ASP.NET的“多个配置文件”功能,并将一个web.config文件放置在ISV文件夹中。但CRM应用程序似乎忽略了我的配置文件。

请告诉我如何在我的自定义ASPX页面上包含AJAX。

谢谢

回答

1

参考MSCRM 4.0扩展MOC,您可以包括在ISV文件夹内您的自定义ASP.NET Web应用程序自己的web.config。

只要注意一下,你就可以删除MapOrg和CrmAuthentication的HttpModules这是由根MS-CRM的web.config中。

这些都是消除的示例代码段两个的HttpModules

<configuration> 
    <system.web> 
    <httpModules> 
     <clear/> 
    </httpModules> 
    </system.web> 
</configuration> 

您也可以参考Ronald Lemmen postCesar post

希望这有助于

哈迪TEO

1

如果您从ISV \ yoursolution \ web.config中删除CrmAuthentication和MapOrg模块,那么您将无法重新使用最终用途r在调用Web服务时的身份。

该解决方案将允许您使用CRM 4.0在UpdatePanel和ScriptManager的不修改CRM的web.config并且不会使您的ISV解决方案文件夹它自己的IIS应用程序。

要做到这一点,我们需要使Web浏览器尝试要求我们的ISV解决方案文件夹中的ScriptResource.axd文件,以修正内容ScriptManager控件的输出与响应滤波器。然后,为了说服脚本资源处理程序处理请求,它必须看起来像是在根目录中请求的,原因有两个。 因此,我们需要创建并连接我们自己的脚本资源处理程序,它将简单地修复并将请求代理到正常处理程序。

拦截和修正内容脚本标签,在你的aspx页面的Load事件:

protected void Page_Load(object sender, EventArgs e) 
{ 
    Response.Filter = new ScriptResourceFixupFilter(Response.Filter); 
} 

然后要连接的处理程序来截取请求,修改您的ISV \ yoursolution \ web.config文件。在配置\的System.Web \ HttpHandlers的部分,注释掉指定路径=“ScriptManager的”添加元素,并插入一个新的附加元素,如下所示:

<!--<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 verb="GET,HEAD" path="ScriptResource.axd" type="YourNamespace.ScriptResourceHandlerProxy, YourAssemblyNameWithoutDllExtension"/> 

请确保您设置的类型属性,使其引用项目中的类名称空间和程序集名称。

然后包括这两个班在您的解决方案:

/// <summary> 
/// This is used to resolve compatibility issues with CRM's web.config, it doesn't have entries required for 
/// the built in System.Web.Handlers.ScriptResourceHandler used Microsoft's ASP.Net Ajax components (i.e. ScriptManager, UpdatePanel, etc...) 
/// 
/// This class will pick up the request for the script resource, 
/// translates the request url so it appears to come at the to the app root path 
/// </summary> 
public class ScriptResourceHandlerProxy : System.Web.Handlers.ScriptResourceHandler 
{ 
    protected override void ProcessRequest(HttpContext context) 
    { 
     // in order to trick the ScriptResourceHandler into handling this request, 
     // we need to show it that the path of the request context is at the root of the web application 
     var uri = new UriBuilder(context.Request.Url.AbsoluteUri) 
     { 
      Path = VirtualPathUtility.ToAbsolute("~/ScriptResource.axd"), 
      Query = null 
     }; 

     var compatableContext = new HttpContext(
      new HttpRequest("ScriptResource.axd", uri.Uri.ToString(), (context.Request.Url.Query ?? String.Empty).TrimStart('?')), 
      context.Response); 

     base.ProcessRequest(compatableContext); 
    } 
} 

/// <summary> 
/// This is used to resolve compatibility issues with CRM's web.config, it doesn't have entries required for 
/// the built in System.Web.Handlers.ScriptResourceHandler used Microsoft's ASP.Net Ajax components (i.e. ScriptManager, UpdatePanel, etc...) 
/// 
/// Replace references to src="/ScriptResource.axd" with "/ISV/YourSolution/ScriptResource.axd" so that the 
/// ASP.Net runtime picks up on our web.config entries that include the asp.net Ajax entries and passes the 
/// request along to our script resource handler proxy class 
/// </summary> 
public class ScriptResourceFixupFilter : MemoryStream 
{ 
    private Stream _output; 
    public ScriptResourceFixupFilter(Stream output) 
    { 
     this._output = output; 
    } 

    public override void Write(byte[] buffer, int offset, int count) 
    { 
     var content = UTF8Encoding.UTF8.GetString(buffer); 
     content = content.Replace(@"""/ScriptResource.axd", @"""/ISV/YourSolution/ScriptResource.axd"); 
     _output.Write(UTF8Encoding.UTF8.GetBytes(content), offset, UTF8Encoding.UTF8.GetByteCount(content)); 
    } 
} 

祝您好运!