VirtualPathProvider - disabling caching hangs serv

2019-08-26 07:58发布

问题:

I have a Virtual Path Provider on a Web site. It does exactly what I want it to do with the simple exception that it hangs the server. This usually only happens if too many requests come in at the roughly the same time.

When I remove the caching overrides altogether the VPP and the server run fine but it caches content which must be dynamic.

The method that I used to disable caching (which works) is simple:

/* AppStart class */
public static void AppInitialize()
{
    string strPath = HostingEnvironment.ApplicationPhysicalPath.ToString();
    WebEI.TextVirtualPathProvider providerInstance = new WebEI.TextVirtualPathProvider();
    HostingEnvironment hostingEnvironmentInstance = (HostingEnvironment)typeof(HostingEnvironment).InvokeMember("_theHostingEnvironment", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null);
    if (hostingEnvironmentInstance == null)
        return;
    MethodInfo mi = typeof(HostingEnvironment).GetMethod("RegisterVirtualPathProviderInternal", BindingFlags.NonPublic | BindingFlags.Static);
    if (mi == null)
        return;
    mi.Invoke(hostingEnvironmentInstance, new object[] { (VirtualPathProvider)providerInstance });
}

/* VPP class */
protected bool IsVirtualPath(string virtualPath)

{
    return false;
}

public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
{
    return null;*/
}

/* DirectoryExists, FileExists, GetFile are typical */}

However, this solution results in hanging the server (Cassini, IIS 6, IIS 7, IIS 8). The hanging only lasts for a few minutes then the results are delivered (I messed with browser timeouts to as part of debugging).

I've also tried including a test for virtual path/file which only disables caching on virtual URLs but with the same results.

To sum up, I simply need and effective way to disable caching in a VPP.

Can anyone help?