8

I have implemented a VirtualPathProvider. The VirtualPathProvider reads the view from File system.

However my problem is the method GetFile(string virtualPath) is not executed every time for every request. I think it is related to the caching, isn't it? What I want is getting file every time for every request. Because for some cases, the page in the file system will be modified and users want the system shows the changes immediately.

Thanks.

Michiel van Oosterhout
  • 22,839
  • 15
  • 90
  • 132
Alex Yeung
  • 2,495
  • 7
  • 31
  • 48
  • Does your provider get called every time when in debug mode? If so, then it's caching, as the view caching is disabled when debug is enabled. – Clicktricity Sep 20 '10 at 22:03
  • Thank you for your response. The VirtualPathProvider is called for every request, but only the `bool FileExists(string virtualPath)` method is called for every request. I have tried to override all methods in the VirtualPathProvider, but I still cannot find the solution. – Alex Yeung Sep 22 '10 at 04:06
  • In fact, I just directly run an example from http://padcom13.blogspot.com/2009/04/virtualpathprovider-example.html. – Alex Yeung Sep 22 '10 at 04:11

2 Answers2

16

I found the solution myself on the internet.

Really thanks jbeall replied on 07-15-2008, 11:05 AM.

http://forums.asp.net/t/1289756.aspx

In short words, overrides the following methods

  1. GetCacheDependency - always return null
  2. GetFileHash - always return different value

After these modifications, for every request, MVC gets the file from source directly.

Alex Yeung
  • 2,495
  • 7
  • 31
  • 48
0
public class MyVirtualPathProvider : VirtualPathProvider
{

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

    }

    public override String GetFileHash(String virtualPath, IEnumerable virtualPathDependencies)
    {
        return Guid.NewGuid().ToString();

    }
}
user3311522
  • 1,638
  • 3
  • 19
  • 33