VirtualPathProvider - disabling caching hangs server (IIS and Cassini)

北慕城南 提交于 2019-12-12 04:49:42

问题


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?

来源:https://stackoverflow.com/questions/45320336/virtualpathprovider-disabling-caching-hangs-server-iis-and-cassini

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!