请首先看如下内容:

未找到视图"Index"或其母版视图,或没有视图引擎支持搜索的位置。搜索了以下位置
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml

版权归二师弟和博客园共同所有,欢迎转载和分享知识。转载请注明出处!

Mvc4和mvc3是这样查找的,其中*.aspx和*.ascx以及*.vbhtml都是我们不需要的。

我们可以想象,这里不管采用什么办法,肯定至少4次访问文件系统并判断对应文件是否存在,才会找到我们的index.cshtml,这样的开销小型应用可以忽略,如果并发量千万级(总之很大,具体未测)肯定对性能有一定影响。

怎么避免,不要去查找*.aspx,*.ascx以及*.vbhtml?

经过几番折腾,我们成功找到了解决办法:

Mvc中有两个视图引擎,webformengine和razorengine,解决办法就是,确定不使用webform的情况下,移除webformengine,然后移除razorengine并添加改写了的razorengine。

移除的代码在global.ascx.cs的application_start方法中这样写:

ViewEngines.Engines.Clear();

重写razorengine的方法:

public class Engine : RazorViewEngine

{

public Engine( )

{

base.AreaViewLocationFormats = new string[]

{

"~/Areas/{2}/Views/{1}/{0}.cshtml",

"~/Areas/{2}/Views/Shared/{0}.cshtml",

};

base.AreaMasterLocationFormats = new string[]

{

"~/Areas/{2}/Views/{1}/{0}.cshtml",

"~/Areas/{2}/Views/Shared/{0}.cshtml",

};

base.AreaPartialViewLocationFormats = new string[]

{

"~/Areas/{2}/Views/{1}/{0}.cshtml",

"~/Areas/{2}/Views/Shared/{0}.cshtml",

};

base.ViewLocationFormats = new string[]

{

"~/Views/{1}/{0}.cshtml",

"~/Views/Shared/{0}.cshtml",

};

base.MasterLocationFormats = new string[]

{

"~/Views/{1}/{0}.cshtml",

"~/Views/Shared/{0}.cshtml",

};

base.PartialViewLocationFormats = new string[]

{

"~/Views/{1}/{0}.cshtml",

"~/Views/Shared/{0}.cshtml",

};

base.FileExtensions = new string[]

{

"cshtml",

};

}

}

然后添加改写的视图引擎:

ViewEngines.Engines.Add(new Engine());

版权归二师弟博客园共同所有,欢迎转载和分享知识。转载请注明出处!

最终application_start方法如下:

最新文章

  1. Linux 系统命令
  2. MemCache
  3. Python学习【第四篇】用户输入及判断
  4. mac(linux) 上如何安装ant
  5. centos6.6编译安装lnmp系列之nginx
  6. ADO.NET数据库操作助手类
  7. HTML JavaScript简介
  8. 使用maven配置基本Mybatis
  9. PHP MySQL 插入多条数据
  10. hibernate 数据关联多对多 4.1
  11. Mac OS X在建筑Python科学计算环境
  12. hdu 4107当卡段树
  13. didMoveToSuperView 引发的思考
  14. 使用Java实现二叉树的添加,删除,获取以及遍历
  15. python中logger模块的应用
  16. vue 用huilder打包APP时,安卓按返回键就退出App改为按两次再退出App
  17. centos 6.4配置samba+ldap认证
  18. Linux 远程登录配置
  19. Android-Java-类与对象的关系
  20. SQLServer2005 CASE WHEN在项目中实例-查询显示值替换

热门文章

  1. ORA-00020: No more process state objects available故障一例
  2. Hacker communities collection
  3. 网格弹簧质点系统模拟(Spring-Mass System by Verlet Integration)附源码
  4. 以最简单的登录为例,诠释JS面向对象的简单实例
  5. [No00000B]MS OFFICE 2013 快捷键大全
  6. Func<T,TResult>泛型委托
  7. ajax设置自定义请求头信息
  8. CSS3之文本阴影text-shadow
  9. js模拟高级语言的重载
  10. usb驱动开发18之设备生命线