开发者

ASP.NET MVC 2 VirtualPathProvider GetFile every time for every request

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

However my problem is th开发者_运维百科e 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.


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.


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();

    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜