VirtualPathProvider - disabling caching hangs server (IIS and Cassini)
Asked Answered
E

0

0

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?

Elflock answered 26/7, 2017 at 7:34 Comment(3)
Not clear how you have written the VirtualApthprovider.Please add how you are doing it.Since you can reproduce the hang scenario,were you able to figure out whhen and where the request takes time.if you can,please add the stacktrace at that point.Grubman
The server hangs outside of the VPP. I've stepped through the code and none of the commands hang. The delay is either before or in between calls to the VPP.Elflock
Since we couldn't solve this issue we have eliminated the VPP. We're using IIS URL rewrites for some of the functionality that the VPP provided. Some was programmed in other ways. But we lost some of the functionality that it provided because we couldn't turn off caching (by the .Net framework).Elflock

© 2022 - 2024 — McMap. All rights reserved.