我发现了这不起作用的原因。事实证明,在 SharePoint 2010 中,路径crossdomain.xml
并被clientaccesspolicy
排除在虚拟路径提供程序之外,因此永远不会从 SharePoint 内容数据库中提供服务。
代码隐藏在 Sharepoint 中SPRequestModule
(见下文)。唯一明智的解决方案是将crossdomain.xml
文件部署到每个 Web 服务器上的 IIS 根目录,这并不理想。
[SharePointPermission(SecurityAction.Demand, ObjectModel=true)]
void IHttpModule.Init(HttpApplication app)
{
if (app is SPHttpApplication)
{
if (!_virtualPathProviderInitialized)
{
lock (_virtualServerDataInitializedSyncObject)
{
if (!_virtualPathProviderInitialized)
{
Dictionary<string, ExclusionAttributes> dictionary = new Dictionary<string, ExclusionAttributes>(StringComparer.OrdinalIgnoreCase);
dictionary["/app_themes"] = ExclusionAttributes.Folder;
dictionary["/app_browsers"] = ExclusionAttributes.Folder;
dictionary["/defaultwsdlhelpgenerator.aspx"] = ExclusionAttributes.File;
dictionary["/clientaccesspolicy.xml"] = ExclusionAttributes.File;
dictionary["/crossdomain.xml"] = ExclusionAttributes.File;
VirtualPathProvider virtualPathProvider = HostingEnvironment.VirtualPathProvider;
if ((virtualPathProvider != null) && virtualPathProvider.DirectoryExists("/"))
{
VirtualDirectory directory = virtualPathProvider.GetDirectory("/");
if (directory != null)
{
IEnumerable children = directory.Children;
if (children != null)
{
foreach (VirtualFileBase base2 in children)
{
string str = base2.VirtualPath.TrimEnd(new char[] { '/' });
ExclusionAttributes attributes = 0;
if (base2.IsDirectory)
{
attributes |= ExclusionAttributes.Folder;
}
else
{
attributes |= ExclusionAttributes.File;
}
dictionary[str] = attributes;
}
}
}
}
_excludedFileList = dictionary;
SPVirtualPathProvider provider2 = new SPVirtualPathProvider();
HostingEnvironment.RegisterVirtualPathProvider(provider2);
_virtualPathProviderInitialized = true;
}
SPTemplateFileSystemWatcher.Local.Initialize();
SPPerformanceCounterAgent current = SPPerformanceCounterAgent.Current;
}
}
app.BeginRequest += new EventHandler(this.BeginRequestHandler);
app.PostAuthenticateRequest += new EventHandler(this.PostAuthenticateRequestHandler);
app.PostAuthorizeRequest += new EventHandler(this.PostAuthorizeRequestHandler);
app.PostResolveRequestCache += new EventHandler(this.PostResolveRequestCacheHandler);
app.PostAcquireRequestState += new EventHandler(this.PostAcquireRequestStateHandler);
app.PreRequestHandlerExecute += new EventHandler(this.PreRequestExecuteAppHandler);
app.PostRequestHandlerExecute += new EventHandler(this.PostRequestExecuteHandler);
app.ReleaseRequestState += new EventHandler(this.ReleaseRequestStateHandler);
app.Error += new EventHandler(this.ErrorAppHandler);
app.PostLogRequest += new EventHandler(this.PostLogRequestHandler);
app.EndRequest += new EventHandler(this.EndRequestHandler);
}
}