1

我有一个自定义 ASPX 页面,我部署在 ISV 文件夹中。该页面包含一个 ScriptManager 控件。

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

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

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

谢谢

4

2 回答 2

1

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

请注意,您可以删除根 MS-CRM web.config 使用的 MapOrg 和 CrmAuthentication HttpModules。

这些是删除两个 HttpModules 的示例代码片段

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

您也可以参考Ronald Lemmen 的帖子Cesar 的帖子

希望这可以帮助,

哈迪特奥

于 2009-07-03T12:46:04.713 回答
1

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

此解决方案将允许您在 CRM 4.0 中使用 UpdatePanel 和 ScriptManager,而无需修改 CRM 的 web.config,也无需将您的 ISV 解决方案文件夹设为自己的 IIS 应用程序。

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

要拦截和修复脚本标签,请在您的 aspx 页面的 Load 事件中:

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

然后连接处理程序以拦截请求,修改您的 ISV\yoursolution\web.config 文件。在 configuration\system.web\httpHandlers 部分,注释掉指定 path="ScriptManager" 的 add 元素并插入一个新的 add 元素,如下所示:

  <!--<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));
    }
}

祝你好运!

于 2012-03-04T17:37:50.877 回答