RouteConfig.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using System.Web.Routing;
  7. namespace EMISOnline.Web
  8. {
  9. public class RouteConfig
  10. {
  11. public static void RegisterRoutes(RouteCollection routes)
  12. {
  13. routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  14. routes.IgnoreRoute("{resource}.zip/{*pathInfo}");
  15. routes.IgnoreRoute("{resource}.rar/{*pathInfo}");
  16. routes.IgnoreRoute("{resource}.7z/{*pathInfo}");
  17. routes.IgnoreRoute("{resource}.xls/{*pathInfo}");
  18. //routes.MapRoute(
  19. // name: "Default",
  20. // url: "{controller}/{action}/{id}",
  21. // defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
  22. //);
  23. //string[] routesArr = new string[]{
  24. // "CalendarManage","EvaluationManage"
  25. //};
  26. //foreach (string name in routesArr)
  27. //{
  28. // routes.MapRoute(
  29. // name, // 路由名称
  30. // name + "/{controller}/{action}/{id}", // 带有参数的 URL
  31. // new { controller = "Menu", action = "Index", id = UrlParameter.Optional }, // 参数默认值
  32. // namespaces: new string[] { "EMIS.Web.Controllers." + name }
  33. // );
  34. //}
  35. routes.MapRoute(
  36. "HTMLDefault", // Route name
  37. "{controller}/List.html", // URL with parameters
  38. new { controller = "Home", action = "List" } // Parameter defaults
  39. );
  40. //默认的路径解析
  41. routes.MapRoute(
  42. "Default", // 路由名称
  43. "{controller}/{action}/{id}", // 带有参数的 URL
  44. new { controller = "Home", action = "Index", id = UrlParameter.Optional } // 参数默认值
  45. );
  46. //默认的路径解析
  47. routes.MapRoute(
  48. "Mange", // 路由名称
  49. "Mange/{controller}/{action}/{id}", // 带有参数的 URL
  50. new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // 参数默认值
  51. namespaces: new string[] { "EMISOnline.Web.Controllers.Mange" }
  52. );
  53. //注册路由寻找规则
  54. ViewEngines.Engines.Clear();
  55. ViewEngines.Engines.Add(new EMISViewEngine());
  56. }
  57. }
  58. public sealed class EMISViewEngine : RazorViewEngine
  59. {
  60. public EMISViewEngine()
  61. {
  62. ViewLocationFormats = new[]
  63. {
  64. "~/Views/{1}/{0}.cshtml",//系统默认规则
  65. "~/Views/Shared/{0}.cshtml",//系统默认规则
  66. "~/Views/Manage/{1}/{0}.cshtml",//我们的规则
  67. "~/Views/StudentView/{1}/{0}.cshtml",//我们的规则
  68. };
  69. }
  70. public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
  71. {
  72. return base.FindView(controllerContext, viewName, masterName, useCache);
  73. }
  74. }
  75. }