如果您从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));
}
}
祝您好运!