using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; namespace EMISOnline.Web { public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{resource}.zip/{*pathInfo}"); routes.IgnoreRoute("{resource}.rar/{*pathInfo}"); routes.IgnoreRoute("{resource}.7z/{*pathInfo}"); routes.IgnoreRoute("{resource}.xls/{*pathInfo}"); //routes.MapRoute( // name: "Default", // url: "{controller}/{action}/{id}", // defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } //); //string[] routesArr = new string[]{ // "CalendarManage","EvaluationManage" //}; //foreach (string name in routesArr) //{ // routes.MapRoute( // name, // 路由名称 // name + "/{controller}/{action}/{id}", // 带有参数的 URL // new { controller = "Menu", action = "Index", id = UrlParameter.Optional }, // 参数默认值 // namespaces: new string[] { "EMIS.Web.Controllers." + name } // ); //} routes.MapRoute( "HTMLDefault", // Route name "{controller}/List.html", // URL with parameters new { controller = "Home", action = "List" } // Parameter defaults ); //默认的路径解析 routes.MapRoute( "Default", // 路由名称 "{controller}/{action}/{id}", // 带有参数的 URL new { controller = "Home", action = "Index", id = UrlParameter.Optional } // 参数默认值 ); //默认的路径解析 routes.MapRoute( "Mange", // 路由名称 "Mange/{controller}/{action}/{id}", // 带有参数的 URL new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // 参数默认值 namespaces: new string[] { "EMISOnline.Web.Controllers.Mange" } ); //注册路由寻找规则 ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new EMISViewEngine()); } } public sealed class EMISViewEngine : RazorViewEngine { public EMISViewEngine() { ViewLocationFormats = new[] { "~/Views/{1}/{0}.cshtml",//系统默认规则 "~/Views/Shared/{0}.cshtml",//系统默认规则 "~/Views/Manage/{1}/{0}.cshtml",//我们的规则 "~/Views/StudentView/{1}/{0}.cshtml",//我们的规则 }; } public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) { return base.FindView(controllerContext, viewName, masterName, useCache); } } }