Global.asax.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.Data.Entity.Infrastructure;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. using System.Web.Routing;
  9. namespace WebS
  10. {
  11. // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明,
  12. // 请访问 http://go.microsoft.com/?LinkId=9394801
  13. public class MvcApplication : System.Web.HttpApplication
  14. {
  15. public static void RegisterGlobalFilters(GlobalFilterCollection filters)
  16. {
  17. filters.Add(new HandleErrorAttribute());
  18. }
  19. public static void RegisterRoutes(RouteCollection routes)
  20. {
  21. routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  22. routes.MapRoute(
  23. "Default", // 路由名称
  24. "{controller}/{action}/{id}", // 带有参数的 URL
  25. new { controller = "Home", action = "Index", id = UrlParameter.Optional } // 参数默认值
  26. );
  27. }
  28. protected void Application_Start()
  29. {
  30. AreaRegistration.RegisterAllAreas();
  31. // 默认情况下对 Entity Framework 使用 LocalDB
  32. Database.DefaultConnectionFactory = new SqlConnectionFactory(@"Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");
  33. RegisterGlobalFilters(GlobalFilters.Filters);
  34. RegisterRoutes(RouteTable.Routes);
  35. }
  36. }
  37. }