自定义虚拟路径提供程序未为无扩展路径调用
本文关键字:路径 扩展 调用 程序 虚拟 自定义 | 更新日期: 2023-09-27 18:06:25
如何确保即使对于没有扩展名的路径也调用自定义虚拟路径提供程序?
例如,如果我在控制器中执行此操作,则不会执行提供程序:
return View("Home");
但是如果我这样做,它被称为:
return View("Home.cshtml");
您使用的是哪个版本的IIS ?您是使用VirtualPathProvider
还是MVC
路由?
您需要确保在II6或II7中具有经典模式的通配符映射。
本文将帮助您了解如何在不同版本的IIS中。除非请求被路由到ASP。. NET你的代码不会被调用,IIS只会返回404
。
在IIS7.5中,您可以尝试添加以下配置。这相当于通配符映射,应该在。net 4中默认启用。
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
我最终添加了一个自定义路径引擎,现在一切似乎都在工作
> private class CustomViewEngine : RazorViewEngine
> {
> private static string[] NewPartialViewFormats = new[] {
> "~/Views/Shared/{0}.cshtml" };
>
> public CustomViewEngine()
> {
> base.PartialViewLocationFormats =
> base.PartialViewLocationFormats.Union(NewPartialViewFormats).ToArray();
> }
> }
在Application_Start: ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new CustomViewEngine());