I get some strange behaviour when I load data via my custom VirtualPathProvider. It might be important to mention, that I am trying to use this view as a layout.
public class MyVirtualPathProvider : VirtualPathProvider
{
public MyVirtualPathProvider()
: base()
{
}
public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
{
if ((virtualPath.StartsWith("/Path/") ||
virtualPath.StartsWith("~/Path/")) && virtualPath.EndsWith(".cshtml"))
{
String name = virtualPath.Replace("/Path/", "").Replace(".cshtml", "");
Uri uri = new Uri("http://www.example.com/Handler.ashx?path=" + name);
return new WebCacheDependency(uri.ToString());
}
return base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
}
public override bool FileExists(string virtualPath)
{
if ((virtualPath.StartsWith("/Path/") ||
virtualPath.StartsWith("~/Path/")) && virtualPath.EndsWith(".cshtml"))
return true;
return base.FileExists(virtualPath);
}
public override VirtualFile GetFile(string virtualPath)
{
if (virtualPath.StartsWith("/Path/") || virtualPath.StartsWith("~/Path/"))
return new TemplateVirtualFile(virtualPath);
return base.GetFile(virtualPath);
}
}
I also have implemented a custom (dummy) CacheDependency
public class WebCacheDependency : CacheDependency
{
public WebCacheDependency(String url)
{
this.SetUtcLastModified(DateTime.UtcNow);
}
}
Now there are two things that don't work. First, all loaded views are being cached and secondly, code inside the file (@Html.ActionLink ... etc.) does not work, It just gives an error "assembly missing".
Has anyone an idea how to remedy those two problems?
There's already a solution of the second problem (link) however I really don't get it how this problem can be solved inside the FileExists method.
Thank you!
Update: An image of the error message