ASP.NET MVC 2 VirtualPathProvider GetFile每次都针对每个请求

时间:2022-10-19 21:50:19

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

我已经实现了VirtualPathProvider。 VirtualPathProvider从文件系统中读取视图。

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.

但是我的问题是每次请求都不会执行GetFile(string virtualPath)方法。我认为这与缓存有关,不是吗?我想要的是每次请求每次都获取文件。因为在某些情况下,文件系统中的页面将被修改,用户希望系统立即显示更改。

Thanks.

谢谢。

2 个解决方案

#1


15  

I found the solution myself on the internet.

我自己在互联网上找到了解决方案。

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

非常感谢jbeall在07-15-2008,11:05 AM回复。

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

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

In short words, overrides the following methods

简而言之,请覆盖以下方法

  1. GetCacheDependency - always return null
  2. GetCacheDependency - 始终返回null
  3. GetFileHash - always return different value
  4. GetFileHash - 始终返回不同的值

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

在这些修改之后,对于每个请求,MVC直接从源获取文件。

#2


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

    }
}

#1


15  

I found the solution myself on the internet.

我自己在互联网上找到了解决方案。

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

非常感谢jbeall在07-15-2008,11:05 AM回复。

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

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

In short words, overrides the following methods

简而言之,请覆盖以下方法

  1. GetCacheDependency - always return null
  2. GetCacheDependency - 始终返回null
  3. GetFileHash - always return different value
  4. GetFileHash - 始终返回不同的值

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

在这些修改之后,对于每个请求,MVC直接从源获取文件。

#2


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

    }
}