我已经设置了一个VirtualPathProvider,它对地址栏中的http://.../home/index这样的直接url调用很好。
public class HomeController
{
public ActionResult Index()
{
// This triggers MyVirtualPathProvider functionallity when called via
// the browsers address bar or anchor tag click for that matter.
// But it does not trigger MyVirtualPathProvider for 'in-view' calls like
// @{ Html.RenderAction("index", "home"); }
return View();
}
}
public class MyVirtualPathProvider : VirtualPathProvider
{
public override System.Web.Hosting.VirtualFile GetFile(string virtualPath)
{
// This method gets hit after the Controller call for return View(...);
if (MyCondition)
return MyVirtualFileHandler.Get(virtualPath);
return base.GetFile(virtualPath);
}
public override bool FileExists(string virtualPath)
{
// This method gets hit after the Controller call for return View(...);
if (MyCondition)
return true;
return base.FileExists(virtualPath);
}
}但是,我希望这也适用于helper,但是现在它忽略了视图中Html助手调用的VirtualPathProvider:
@{
Html.RenderAction("index", "home");
}有办法解决这个问题吗?
另外,我对WebViewPage有一个覆盖,这样我就能够重写帮助程序的初始化,但是我不知道什么或者如何。
编辑:
我已经在两台电脑上试过了,奇怪的是,它能在另一台电脑上工作。所以问题实际上是:
为什么VirtualPathProvider在一台计算机上工作,而在另一台计算机上却失败了50%?但这样的话,这个问题就会变得有些模糊,甚至是推测性的。尽管如此,我对此并不满意,但我似乎不得不重新安装一些东西。:(
发布于 2013-12-22 18:33:17
用户LostInComputer很好地提交了一个在我笔记本上工作的示例项目,我对其中的不同之处感到困惑。
通常,人们会期望helpers只为VirtualPathProvider工作,现在我知道它应该工作了。
实际的问题在于安装了特定的pc,我在那里遇到了问题,在重新安装之后,一切都很好。所以这并不是一个复杂的解决方案,但由于这个问题很少被关注,我至少给出了我自己的答案,因为有一天,这对其他人来说可能是有用的东西,它可能会变得多么乏味。:)
当您肯定希望某些东西能够正常工作时,您可以尝试在另一台机器上运行它(当然,如果有可用的话),因为最终可能出错的可能只是一个损坏的安装。
https://stackoverflow.com/questions/20608672
复制相似问题