Asp.net MVC area文件夹下设置默认显示页面
来源:互联网 发布:《算法统宗》的题目 编辑:程序博客网 时间:2024/05/20 02:28
在使用area 的时候,设置默认的显示页面,经常会碰到如下异常:
“/”应用程序中的服务器错误。
未找到视图“Index”或其母版视图,或没有视图引擎支持搜索的位置。搜索了以下位置: ~/Views/index/Index.aspx~/Views/index/Index.ascx~/Views/Shared/Index.aspx~/Views/Shared/Index.ascx~/Views/index/Index.cshtml~/Views/index/Index.vbhtml~/Views/Shared/Index.cshtml~/Views/Shared/Index.vbhtml
但直接输入url地址却可以访问。这时就是Global.asax文件的配置有问题了。具体配置如下:
public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // 路由名称 "{controller}/{action}/{id}", // 带有参数的 URL new { controller = "index", action = "Index", id = UrlParameter.Optional }, // 参数默认值 new string[] { "Index.Controllers" } //默认控制器的命名空间 ).DataTokens.Add("area", "index"); //默认area 的控制器名称 } protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); }
文件 IndexAreaRegistration.cs 的配置如下:
public class IndexAreaRegistration : AreaRegistration { public override string AreaName { get { //项目名称 如与区域名称不一致,则需要更改生成事件的批处理 return "Index"; } } public override void RegisterArea(AreaRegistrationContext context) { //路由规则小写 context.MapRoute( "index_default", "index/{controller}/{action}/{id}", new { controller = "indexhome", action = "index", id = UrlParameter.Optional } ); } }
1 0
- Asp.net MVC area文件夹下设置默认显示页面
- asp.net mvc设置area页面为默认路由
- ASP.NET MVC Area操作
- asp.net mvc Area使用
- ASP.NET MVC系列:Area
- asp.net设置页面默认按钮
- ASP.NET MVC中的Area区域简介
- 设置ASP.NET MVC站点默认页为html页
- 设置ASP.NET MVC站点默认页为html页
- asp.net设置默认打开页面 Web.config defaultDocument
- asp.net设置默认打开页面 Web.config defaultDocument
- asp.net中页面按钮回车默认执行 设置方法
- ASP.NET MVC中Area分层模块处理大解密 下
- asp.net mvc 远程校验Remote属性在Area下验证路径不正确的解决
- 【ASP.NET MVC】应用程序文件夹
- asp.net mvc && asp.net 页面跳转
- ASP.NET MVC页面执行时间
- ASP.NET MVC中Area分层模块处理大解密
- auto_ptr
- 在服务器端判断request来自Ajax请求(异步)还是传统请求(同步)
- VC6.0中clw、ncb、aps文件的作用
- effective C++ 阅读笔记 1
- C内存对齐
- Asp.net MVC area文件夹下设置默认显示页面
- NYOJ 525 一道水题
- 自定义“打开/另存为”对话框左侧快捷方式列表
- XP远程桌面mstsc和带参数的mstsc /console
- Cocos2d的特性
- Hadoop2.2.0完全分布式集群平台安装与设置-入门级手把手
- 使用函数的多个返回值
- Mysql实现分区功能(二)
- mysql数据库的备份以及表格数据之间的复制